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?