The following code works with my user in my OneDrive for business to download some file, but when I try access to another OneDrive company where my user has permissions it returns 403 forbidden. I looked for it but I saw nothing clear. Can someone put me on the right track?
//string fileUrl = "http://ift.tt/1vPNbIa";
string fileUrl = "http://ift.tt/1ypiFHa";
string localPath = "C:/path/file.xlsx";
string username = myUser@myCompany.com;
String pwd = pass;
System.Net.WebClient client = new System.Net.WebClient();
client.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
//client.Headers.Add("user-agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
SecureString password = new SecureString();
foreach (char c in pwd.ToCharArray())
{
password.AppendChar(c);
}
client.Credentials = new SharePointOnlineCredentials(username, password);
client.DownloadFile(fileUrl, localPath);

0 commentaires:
Enregistrer un commentaire