SharePoint客户端对象模型返回"无法找到用户"在clientContext.ExecuteQuery()方法

时间:2016-05-26 06:47:48

标签: model-view-controller office365 csom

SharePoint客户端对象模型返回"无法找到用户"在 clientContext.ExecureQuery()方法中,下面是示例代码。

        ListItemCollection listItemColl = null;
        var securePassword = new System.Security.SecureString();
        var pwd = WebConfigurationManager.AppSettings["password"];

        foreach (char c in pwd)
        {
            securePassword.AppendChar(c);
        }

        var spUri = ConfigurationManager.AppSettings["Office365SharepointUri"];
        var clientContext = new ClientContext(new Uri(spUri));
        var onlineCredentials = new SharePointOnlineCredentials(WebConfigurationManager.AppSettings["userName"], securePassword);

        clientContext.Credentials = onlineCredentials;

        try
        {
            var strCamlQuery = new CamlQuery();                
            clientContext.Load(clientContext.Web);                
            var templist = clientContext.Web.Lists.GetByTitle("SomeValidListName");
            clientContext.Load(templist);                
            strCamlQuery.ViewXml = "<View Scope=\"RecursiveAll\"></View>";
            listItemColl = templist.GetItems(strCamlQuery);
            clientContext.Load(listItemColl);
            clientContext.ExecuteQuery();
        }
        catch (Exception)
        {
            throw;
        }

我正在提供有效的凭据,甚至能够通过浏览器访问具有相同提供的凭据的SharePoint网站而没有任何问题。

之前任何人都面临这个问题吗?

环境: MVC 5应用程序。 CSOM。 视觉工作室。 C#

1 个答案:

答案 0 :(得分:3)

这是SharePoint中的Bug,我采用了SharePoint高级支持。

如果完全删除了创建这些列表的用户,当您尝试访问这些列表时,CSOM会抛出“无法找到用户”异常,SP会在内部检查创建该列表的用户。

解决方案是重新创建具有不同用户的列表。希望SP团队解决这个问题。

感谢您的回答。