我使用以下代码从SharePoint列表中获取用户:
private ClientContext clientContext = new ClientContext(siteUrl); private SP.List oList = clientContext.Web.Lists.GetByTitle("SharePoint List"); private CamlQuery camlQuery = new CamlQuery(); private ListItemCollection collListItem = oList.GetItems(camlQuery); private ArrayList names = new ArrayList(); clientContext.Load(collListItem, items => items.Include( item => item["UserNames"])); clientContext.ExecuteQuery(); foreach (ListItem oListItem in collListItem) { titles.Add(oListItem["UserNames"]); }
我也从其他列中检索数据,我得到的数据就好了.但是当谈到名称时,返回值就是Microsoft.SharePoint.Client.FieldUserValue
.
有关如何获取实际用户名的任何建议?
它应该返回FieldUserValue,您可以从对象中获取用户名或ID.这是一个简单的例子:
FieldUserValue user = (FieldUserValue)listItem["Author"]; string name = user.LookupValue;