【问题标题】:(401) Unauthorized Error working with Client Object Model(401) 使用客户端对象模型时出现未经授权的错误
【发布时间】:2011-11-19 23:49:30
【问题描述】:

我正在尝试从共享点站点检索文档库列表,这是我的代码,这是一个 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)

而且我确定凭据是正确的,

关于这个的任何线索,

谢谢,

【问题讨论】:

    标签: sharepoint-2010


    【解决方案1】:

    这个问题看起来很老,但是为了其他可能查看这个问题的人的利益,只有可能的问题会导致这个问题。

    1. 登录凭据(丢失或不正确)
    2. 客户端和服务器之间的代理/防火墙不允许通信通过。

    【讨论】:

      猜你喜欢
      • 2018-07-07
      • 2022-11-11
      • 2017-07-31
      • 2021-01-07
      • 1970-01-01
      • 1970-01-01
      • 2022-11-09
      • 2020-12-17
      • 2014-11-03
      相关资源
      最近更新 更多