Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting The Proper Name Value Instead Of Microsoft.SharePoint.Client.FieldUserValue

I am using the following code to get users from a SharePoint list:

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"]);
        }

I am retrieving data from another columns, too, and I get those data just fine. But when it comes to names, the return value is the Microsoft.SharePoint.Client.FieldUserValue.

Any suggestions on how to get the actual usernames?

like image 513
Istvan Avatar asked Dec 10 '15 14:12

Istvan


1 Answers

It's supposed to return FieldUserValue, you can get the users name or ID from the object. Here's a quick example:

FieldUserValue user = (FieldUserValue)listItem["Author"];
string name = user.LookupValue; 
like image 174
Arcan.NET Avatar answered Nov 16 '22 22:11

Arcan.NET