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が発生する
前もって感謝します。