2010-10-14 92 views
4

我tryiing从SharePoint网站检索文档库的列表,这里是我的代码,这是一个Windows应用程序(401)未经授权错误与客户端对象模型的工作

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

这个问题看上去很旧,但对于其他可能针对这一问题的利益,只有导致这种可能出现的问题。

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