0

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.

Community
  • 1
  • 1
barathan
  • 21
  • 1
  • 4

1 Answers1

0

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

Ryan
  • 23,871
  • 24
  • 86
  • 132
  • Hi Ryan, Thank you for your input. We already used the SharePoint object model. But we are getting com Exception, when file size is exceed 100kb. Please refer the below [link](http://stackoverflow.com/questions/3924491/getting-comexception-while-reading-the-document-in-sharepoint-2010)(http://stackoverflow.com/questions/3924491/getting-comexception-while-reading-the-document-in-sharepoint-2010) – barathan Sep 27 '11 at 06:41