首页 > 解决方案 > 如何修复'值不能为空。参数名称:在 SharePoint Online 中使用 CSOM 的 key 异常

问题描述

我尝试使用 C# 从 SharePoint Online 网站检索一些数据。我有两个不同的 SharePoint 网站(如 site1.sharepoint.com 和 site2.sharepoint.com)。我使用相同的代码来检索日期,我可以从 site1.sharepoint.com 检索并且工作正常,但我无法从 site2.sharepoint.com 检索。

site1 是我们的组织租户,这意味着安全设置已更改,同时 site2 为默认设置(自创建以来未更改任何设置)。

问题可能出在site1吗?如果是,哪些设置会产生这样的错误?

谢谢

    private async Task<ListItemCollection> GetIntentFilterData(string url, string content, string columnName, string columnValue)
    {
        string siteUrl = url;

        string login = _configuration["Login"];
        string password = _configuration["Password"];

        string listName = content;

        try
        {

            using (ClientContext clientContext = new ClientContext(siteUrl))
            {

                clientContext.Credentials = new SharePointOnlineCredentials(login, password);

                List oList = clientContext.Web.Lists.GetByTitle(listName);
                CamlQuery camlQuery = new CamlQuery();
                camlQuery.ViewXml = string.Format(@"<View>                              
                                                    <Query> 
                                                    <Where>
                                                    <Contains>                                                        
                                                    <FieldRef Name='BaseName'/>                                        
                                                    <Value Type='Lookup'>" + columnValue + @"</Value>                                                                                            
                                                    </Contains>                                                                                                            
                                                    <FieldRef Name='EncodedAbsUrl'/>                                           
                                                    <Value Type='Lookup'>" + columnValue + @"</Value>                                                                                                                                                  
                                                    </Where>                                
                                                    </Query>                                                    
                                                    </View>", "Some specific item");

                ListItemCollection collListItem = oList.GetItems(camlQuery);
                clientContext.Load(collListItem, items => items.Include(item => item["EncodedAbsUrl"], item => item["BaseName"]));

                await clientContext.ExecuteQueryAsync(); // this line throws the exception.
                return collListItem;
            }
        }
        catch (Exception e)
        {
            // The error is "Value cannot be null.\r\nParameter name: key"
            throw;
        }
    }

我期待从site2(文件列表)获得的相同结果。我现在得到的结果是

标签: c#sharepointsharepoint-online

解决方案


推荐阅读