好吧,我正在使用Caml查询从共享点列表中检索项目.我得到项目循环通过字段值到我想要的那个.我的问题是我需要将FieldUserValue数据类型转换为普通的User数据类型.有一种从User检索FieldUserValue的方法,但不是相反的方法...
User Usr;
foreach (ListItem item in items)
{
foreach (var f in item.FieldValues)
{
if (f.Key == "ColumnTitleofDataTypePersonorGroup")
{
//Error Message
Usr = f.Value;
}
}
}
Run Code Online (Sandbox Code Playgroud)
详细的ErrorMessages说错误2无法将类型'object'隐式转换为'Microsoft.SharePoint.Client.User'.存在显式转换(你是否错过了演员表?)
我想我只是遗漏了一些明显的东西......感谢提前任何帮助..
以下示例演示如何从FieldUserValue对象获取User 对象:
var list = ctx.Web.Lists.GetByTitle(listTitle);
var item = list.GetItemById(itemId);
ctx.Load(item);
ctx.ExecuteQuery();
var author = (Microsoft.SharePoint.Client.FieldUserValue) item["Author"];
var authorUser = ctx.Web.SiteUsers.GetById(author.LookupId);
ctx.Load(authorUser);
ctx.ExecuteQuery();
Run Code Online (Sandbox Code Playgroud)