We developed WebPart to read the contents of a file in a document library in SiteCollection. I used the following code to read the content.
WebClient wc = new WebClient();
wc.Credentials = CredentialCache.DefaultNetworkCredentials;
string documenturl = siteurl+"/" + file.Url.ToString();
content = wc.DownloadData(documenturl);
But I got the following error message 401 unathorized
System.Net.WebException: The remote server returned an error:(401) Unauthorized. at System.Net.WebClient.DownloadDataInternal(Uri address,WebRequest& request) at System.Net.WebClient.DownloadData(Uri address)
For your information, I have already tried to load a document using the SPFile openBinary method. But it only works with a small document. Please refer to the site below.
getting a ComException while reading a document in SharePoint 2010
Thanks in advance.
source
share