c# - 如何修复'值不能为空。参数名称:在 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(文件列表)获得的相同结果。我现在得到的结果是
解决方案
推荐阅读
- sql - 大查询正则表达式提取
- angular - 带有绑定数据的 Angular UI 在点击发生之前不会显示
- mysql - 我有一条消息 MySQL ERROR 1241 (21000) Operand should contain 1 column(s)
- java - 如何在 Cucumber 框架中正确使用 TestNG 注释
- javascript - 对象数组的Javascript通用搜索
- python - 如何检查音符是否已在音频文件中播放
- javascript - 将猫鼬查找查询的结果返回到外部变量
- javascript - TypeError: undefined is not a function (near '...data.map...') - React Native
- sql - 在 BigQuery 中对串联字符串(行)进行分组
- python - python selenuim 代理错误 neterror?e=dnsNotFound