Get Error 401 when trying to download a document from a library programatically
-
09-12-2019 - |
Question
I'm trying to download a document with this code :
using (Impersonator impersonator = new Impersonator())
{
siteURL += "?NoRedirect=true";
System.Net.WebClient _WebClient = new System.Net.WebClient();
// Downloads the resource with the specified URI to a local file.
_WebClient.DownloadFile(siteURL, saveName);
}
But i get an error 401 unothaurized access. Do you have any idea where it come froms ? Thanks
Solution
Try adding:
_WebClient.Credentials = CredentialCache.DefaultCredentials;
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange