A
avs sai
Guest
Hi,
I am new to C#. i want to download files from sharepoint document library. I have used below code I got Forbidden 403 erro while downloading the files.
const string username = "myname.lastname@abc.com";
const string password = "Mypassword265";
const string url = "https://abc.sharepoint.com/sites/Myfolder/";
var securedPassword = new SecureString();
foreach (var c in password.ToCharArray()) securedPassword.AppendChar(c);
//var credentials = new SharePointOnlineCredentials(username, securedPassword);
var credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
//client.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
DownloadFilesFromSharePoint(url, credentials, "Shared Documents/MyFilename.xls");
static void DownloadFilesFromSharePoint(string webUrl, ICredentials credentials, string fileRelativeUrl)
{
using (var client = new WebClient())
{
client.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
client.Credentials = credentials;
WebClient webClient = new WebClient();
webClient.Headers.Add("user-agent", "Only a test!");
webClient.DownloadFile(webUrl, fileRelativeUrl);
}
}
Dts.TaskResult = (int)ScriptResults.Success;
}
Please help me with code.
Thanks
Sravanthi
Continue reading...
I am new to C#. i want to download files from sharepoint document library. I have used below code I got Forbidden 403 erro while downloading the files.
const string username = "myname.lastname@abc.com";
const string password = "Mypassword265";
const string url = "https://abc.sharepoint.com/sites/Myfolder/";
var securedPassword = new SecureString();
foreach (var c in password.ToCharArray()) securedPassword.AppendChar(c);
//var credentials = new SharePointOnlineCredentials(username, securedPassword);
var credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
//client.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
DownloadFilesFromSharePoint(url, credentials, "Shared Documents/MyFilename.xls");
static void DownloadFilesFromSharePoint(string webUrl, ICredentials credentials, string fileRelativeUrl)
{
using (var client = new WebClient())
{
client.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
client.Credentials = credentials;
WebClient webClient = new WebClient();
webClient.Headers.Add("user-agent", "Only a test!");
webClient.DownloadFile(webUrl, fileRelativeUrl);
}
}
Dts.TaskResult = (int)ScriptResults.Success;
}
Please help me with code.
Thanks
Sravanthi
Continue reading...