私は次のコードスニペットを使用してSharePointサーバAPIを接続しています。このスニペットは、期待どおり空のプロジェクトでうまく機能します。 Announcements、Shared Documents、Tasks ...などのリストを返します。リモートサーバからエラーが返されました:(401)context.ExecuteQuery():ASP.Net
これを既存のアプリケーションと統合すると、The remote server returned an error: (401) Unauthorized
というエラーメッセージがcontext.ExecuteQuery()
にスローされます。
同じエラーを返すContext.Credentials = new NetworkCredential(username, password, domain);
を提供しようとしました。
コード:
using (ClientContext context = new ClientContext(ServerUrl))
{
//get all the lists from sharepoint
//all the files and folders resides inside some list.
Web web = context.Web;
context.Load(web.Lists, its => its.Include(it => it.Title, it => it.Id, it => it.RootFolder.ServerRelativeUrl));
context.ExecuteQuery();
foreach (var list in web.Lists)
{
//add all the lists to treeview
//list id is assigned to node value and list's server relative url is assigned to tooltip
tvItems.Nodes.Add(new Telerik.Web.UI.RadTreeNode
{
Value = list.Id.ToString(),
Text = list.Title,
ExpandMode = Telerik.Web.UI.TreeNodeExpandMode.ServerSide,
ToolTip = list.RootFolder.ServerRelativeUrl
});
}
}
私は、SharePointの参照は、一度、既存と混合し得ないことを確認するcontext.Load(web.Lists, its => ClientObjectQueryableExtension.Include(...));
へのコードのcontext.Load(web.Lists, its => its.Include(...);
行を変更してみました。
問題を解決する助けがあれば助かります。
を、あなたは次のリンクをチェックしてみてください、明示的に資格情報の詳細を提供する必要があります: http://stackoverflow.com/questions/5708084/how-do-i-supply-credentials-to-execute-a-query-on-a-server-thats-part-of-anothe –