问题描述
我们开发了一个 WebPart 来读取 SiteCollection 中文档库中文件的内容.我使用以下代码读取内容.
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
但是,我收到以下错误 401 未经授权的异常
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)
为了您的信息,我已经尝试通过 SPFile openBinary 方法下载文档.但它只适用于文档很小的情况.请参考以下网站.
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.
在 SharePoint 2010 中阅读文档时获取 ComException一个>
提前致谢.
推荐答案
可能是 本地环回检查.(通过在 SharePoint 服务器上运行的 IE 尝试使用相同的 URL 访问您的网站来验证)
Probably the local loopback check. (Verify by trying to access your site using the same URL whilst using IE running on your SharePoint server)
另外 - 您使用 Web 服务访问本地内容而不是 SharePoint 对象模型 (Microsoft.SharePoint.dll) 的任何原因?
Also - any reason why you're using web services to access local content rather than the SharePoint object model (Microsoft.SharePoint.dll)?
这篇关于从文档库 SharePoint 2010 读取数据时出现 401 未经授权的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!