401 unauthorized exception while reading data from the document library SharePoint 2010

假装没事ソ 提交于 2019-12-12 02:40:55

问题


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:


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)?



来源:https://stackoverflow.com/questions/7554659/401-unauthorized-exception-while-reading-data-from-the-document-library-sharepoi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!