WebRelativeUrl = "/" + webUrl.Split(new char, 4) WebUrl = webUrl.EndsWith("/") ? webUrl.Substring(0, webUrl.Length - 1) : webUrl
public static void DownloadFileViaRestAPI(string webUrl, ICredentials credentials, string documentLibName, string fileName, string path)
#C# webclient file credentials code
You could refer to the code provided by official document.Īs I test,it works well. However I have been unable to find any recent documentation on what we're supposed to use now. This is similar to Download File From SharePoint 365 which is using what looks like the same code as I am, but Download Document from SharePoint Online using c# webclient stopped working suggests that something has changed and this form of authentication no longer works for connecting to SharePoint online. ("user-agent", "Mozilla/4.0 (compatible MSIE 6.0 Windows NT 5.2. I've tried adding a couple different user agents in the header to see if that helps. I logged out and logged into the SharePoint environment using the same credentials, to ensure that they are correct. Var credentials = new SharePointOnlineCredentials(username, securedPassword) Ĭ("X-FORMS_BASED_AUTH_ACCEPTED", "f") Ĭlient.DownloadFile(url, "C: emp est.pdf") //this file path definitely exists Var securedPassword = new SecureString() įoreach (var c in password.ToCharArray()) const string username = string password = "mypassword" net 4.8 WebClient and the package, trying to download files from SharePoint online.