401 unauthorized exception while reading data from

2019-09-04 15:01发布

We developed a WebPart to read the content of the file in the document library in the 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 401 unathorized exception

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 already tried to download document by SPFile openBinary method. But it only works when the document is small. Please refer the below site.

getting ComException while reading the document in SharePoint 2010

Thanks in advance.

1条回答
欢心
2楼-- · 2019-09-04 15:39

Probably the local loopback check. (Verify by trying to access your site using the same URL whilst using IE running on your SharePoint server)

Also - any reason why you're using web services to access local content rather than the SharePoint object model (Microsoft.SharePoint.dll)?

查看更多
登录 后发表回答