我正在尝试从sharepoint站点检索文档库列表,这是我的代码,这是一个Windows应用程序
public string[] GetDocumentLibraries(ClientContext ctx)
{
Collection<string> libraries = new Collection<string>();
try
{
//Getting the site from the SP context
Web oWebsite = ctx.Web;
write("INFO: SP site gotten");
//Getting the list collection from the SP site
write("INFO: Getting the list collection from the SP site");
ListCollection listCollect = oWebsite.Lists;
write("INFO: Loading the list");
ctx.Load(listCollect);
write("INFO: Getting the list");
ctx.ExecuteQuery();
write("INFO: List Collection size: " + listCollect.Count);
//Getting the list of document libraries
foreach (List docLibList in oWebsite.Lists)
{
if (docLibList.BaseTemplate == (int)ListTemplateType.DocumentLibrary)
{
write("INFO: Document Library: " + docLibList.Title);
libraries.Add(docLibList.Title);
}
}
}
catch (Exception e)
{
write("ERROR: Error getting the list of document libraries, error detail " + e.Message + " " + e.StackTrace);
}
return libraries.ToArray();
}
我在三个不同的SharePoint服务器上尝试过这个代码,它在其中两个中运行,但在第三个中我得到了这个异常
ERROR: Error getting the list of document libraries, error detail The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at P_DocumentImporter.DocumentImporter.GetDocumentLibraries(ClientContext ctx)
我确信凭证是正确的,
关于此的任何线索,
谢谢,
答案 0 :(得分:0)
这个问题看起来很旧,但为了其他可能会查看此问题的人的利益,只有可能导致此问题的问题。