0

SiteCollectionのドキュメントライブラリにあるファイルのコンテンツを読み取るためのWebPartを開発しました。次のコードを使用してコンテンツを読み取りました。

 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

しかし、私は次のエラー401unathorized例外を受け取りました

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)

参考までに、私はすでにSPFileopenBinaryメソッドでドキュメントをダウンロードしようとしました。ただし、ドキュメントが小さい場合にのみ機能します。以下のサイトを参照してください。

SharePoint2010でドキュメントを読んでいるときにComExceptionが発生する

前もって感謝します。

4

1 に答える 1

0

おそらくローカル ループバック チェックです。(SharePoint サーバーで実行されている IE を使用しているときに、同じ URL を使用してサイトにアクセスして確認してください)

また、SharePoint オブジェクト モデル (Microsoft.SharePoint.dll) ではなく Web サービスを使用してローカル コンテンツにアクセスしている理由はありますか?

于 2011-09-26T13:21:22.733 に答える