I want to return all info for a specified user. The internal field name is UserAssigned. If I use this
foreach (ListItem listItem in listItemCollection)
{
Console.WriteLine(listItem[“UserAssigned”]);
}
I get Microsoft.SharePoint.Client.FieldUserValue
returned. How can I translate that to either set my CAML query to return everything for ID 31836 OR username Jones, Jack?
This is C# and CSOM
EDIT
This is the syntax I have...
string siteURL = "";
var ctx = new ClientContext(siteURL);
var web = ctx.Web;
List list = web.Lists.GetByTitle("ListTitle");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "";
var listItemCollection = list.GetItems(camlQuery);
ctx.Load(listItemCollection,
eachItem => eachItem.Include(
item => item,
item => item["ID"],
item => item["UserAssigned"]
));
ctx.ExecuteQuery();
foreach (ListItem listItem in listItemCollection)
{
Console.WriteLine(listItem["ID"];
FieldUserValue un = (FieldUserValue)listItem["UserAssigned"];
string unGood = un.LookupValue;
Console.WriteLine(unGood);
}
Console.ReadLine();
Edit 2
I edited my syntax to be the below - but it is ignoring my where clause...
User user = ctx.Web.CurrentUser;
ctx.Load(user);
ctx.ExecuteQuery();
string itsme = user.Title;
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = string.Format("<Where><Eq><FieldRef Name='UserAssigned' /><value Type='User'>{0}</Value></Eq></Where>", itsme);
var listItemCollection = list.GetItems(camlQuery);
ctx.Load(listItemCollection,
eachItem => eachItem.Include(
item => item,
item => item["ID"],
item => item["UserAssigned"]
));
ctx.ExecuteQuery();
foreach (ListItem listItem in listItemCollection)
{
Console.WriteLine(listItem["ID"];
FieldUserValue un = (FieldUserValue)listItem["UserAssigned"];
string unGood = un.LookupValue;
Console.WriteLine(unGood);
}
Console.ReadLine();