简体   繁体   中英

Download a File from SharePoint Online C#

Refering to: Download File From SharePoint 365

I am using the exact same code and am getting the 401 "unauthorized" exception.

I also added the useDefaultCredentials=True , but no difference.

And the SharePoint.Online.CSOM is not working in.Net Core so i´m using TTCUE.

using (var client = new WebClient())
{
     SharePointOnlineCredentials Creds = new SharePointOnlineCredentials(username, password);       
     client.UseDefaultCredentials = true;
     client.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
     client.Headers.Add("User-Agent: Other");
     client.Credentials = Creds;
     Console.WriteLine(rootSite + sourceSite + folderSite + fileSite);
     client.DownloadFile(rootSite+sourceSite+folderSite+fileSite, destinationPath);
}

4 days ego there was an update on the Microsoft.SharePointOnline.CSOM to also include .NET Standard versions. So now You may use it in .NET Core version. Please refer to this article https://developer.microsoft.com/en-us/sharepoint/blogs/net-standard-version-of-sharepoint-online-csom-apis/ In the movie in this blog post You may see what is the proper authentication method now that is based on tokens

hope this will be of any help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM