【发布时间】:2016-03-26 06:52:00
【问题描述】:
我正在使用以下代码 sn-p 连接共享点服务器 API。正如预期的那样,这个 sn-p 在空白项目中运行良好。它返回列表公告、共享文档、任务...等。
但是当我将它与现有应用程序集成时,它会在 context.ExecuteQuery() 中抛出 The remote server returned an error: (401) Unauthorized 错误消息。
我尝试提供返回相同错误的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
});
}
}
我尝试将 context.Load(web.Lists, its => its.Include(...); 代码行更改为 context.Load(web.Lists, its => ClientObjectQueryableExtension.Include(...)); 以确保共享点引用不会与现有的一次混合。
任何帮助都会很好地解决这个问题。
【问题讨论】:
-
由于它是一个 Web 进程,您需要明确提供凭据详细信息,请查看以下链接并尝试:stackoverflow.com/questions/5708084/…
标签: c# asp.net sharepoint