c# - 获取正确的名称值而不是 Microsoft.SharePoint.Client.FieldUserValue

标签 c# sharepoint field

我正在使用以下代码从 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; 

关于c# - 获取正确的名称值而不是 Microsoft.SharePoint.Client.FieldUserValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34204436/

相关文章:

c# - 是否可以使派生类的字段也被派生?

c# - 从 sharepoint 2010 服务器读取文件夹和文件属性,例如 UniqueId

mysql:使用一个字段包含多个 "fields"来保存字段

c# - 智能感知中缺少配置成员

c# - 在 Windows 10 中将 Datacontext 作为 CommandParameter 传递给 Viewmodel

c# - 为 Windows 10 开发自定义虚拟键盘

c# - MVC - 为 'Html.ValidationMessage' 或 'Html.TextBox' 更改或添加类

sharepoint - 我的应用程序通过 Web 客户端/WebDAV(WebDAV 重定向器)编辑 SharePoint 中的文件。我如何退房/入住?

excel - 如何使用 VBA 或 Powershell 将列表从具有 NTLM 身份验证的 Sharepoint 服务器导出到 Excel

python - 假设您向结构化数组的一维切片添加了一个新字段,为什么不能将新字段的条目设置为列表?