401 Unauthorized exception while reading data from a SharePoint 2010 document library

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);//documenturl is the file path of the document

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.

0
source share
1 answer

, . (, URL- IE, SharePoint)

- - , SharePoint (Microsoft.SharePoint.dll)?

0

All Articles