1

I have a SharePoint 2013 app where I want to download a file. in the web project I get the url from a file in SharePoint and I want to download it using the following code:

WebClient webClient = new WebClient();
webClient.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
webClient.Credentials = new NetworkCredential(userName, password, domain);
byte[] fileData = webClient.DownloadData(docUrl);
FileStream file = System.IO.File.Create(@"C:\local\");
file.Write(fileData, 0, fileData.Length);

But i get an error 401: Unauthorized

How can I download the file from SharePoint in the web project with the URL of the file?

1 Answer 1

1

SharePoint Apps don't have access to the file system directly. You could download a file and save it to a SharePoint library, but you wouldn't be able to save it directly to the local file system. See http://msdn.microsoft.com/en-us/library/dn268593.aspx for some considerations between a SharePoint App and a SharePoint Farm Solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.