C#将Microsoft.Sharepoint.Client.FieldUserValue转换为Microsoft.Sharepoint.Cliend.User
好的,我正在使用Caml查询从sharepoint列表检索项目。我通过字段值得到我想要的项循环。我的问题是我需要将FieldUserValue数据类型转换为普通用户数据类型。有一种方法可以从用户处检索FieldUserValue,但不是相反的方法C#将Microsoft.Sharepoint.Client.FieldUserValue转换为Microsoft.Sharepoint.Cliend.User,c#,sharepoint,C#,Sharepoint,好的,我正在使用Caml查询从sharepoint列表检索项目。我通过字段值得到我想要的项循环。我的问题是我需要将FieldUserValue数据类型转换为普通用户数据类型。有一种方法可以从用户处检索FieldUserValue,但不是相反的方法 User Usr; foreach (ListItem item in items) { foreach (var f in item.FieldValues) {
User Usr;
foreach (ListItem item in items)
{
foreach (var f in item.FieldValues)
{
if (f.Key == "ColumnTitleofDataTypePersonorGroup")
{
//Error Message
Usr = f.Value;
}
}
}
详细的错误信息说
错误2无法将类型“object”隐式转换为“Microsoft.SharePoint.Client.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();