[CSOM]取ListItem的modofiedBy值报microsoft.sharepoint.client.serverexception: 'user cannot be found.'错误

场景
取得ListItem的最后修改人信息。

使用ModifiedBy去得到值,一开始跑了几个site都正常的,但是突然报了microsoft.sharepoint.client.serverexception: 'user cannot be found.'的错误,网站上面找到了相对应的library里面的那个报错的item,发现是有modified By的值的:但是用item.File.ModifiedBy去取,返回的是null,然后才出问题的。

//循环取得每个Item的
foreach(var item in allItems){
	clientContext.Load(item.File.ModifiedBy);
	clientContext.ExecuteQuery();
	System.Windows.Forms.MessageBox.Show(item.File.ModifiedBy.Title);
}

解决方法:

//循环取得每个Item的
foreach(var item in allItems){
	clientContext.Load(item["Editor"]);
	clientContext.ExecuteQuery();
	
	//item["Editor"]返回的是FieldUserValue对象,并不是string
	var editor = item["Editor"] as FieldUserValue;
	System.Windows.Forms.MessageBox.Show(editor.LookupValue);
}


猜你喜欢

转载自blog.csdn.net/WendyXu8230/article/details/88428439