I am trying to return several User-type fields from SharePoint 2013 like this:
using (var clientContext = new ClientContext(myUrl))
{
var list = clientContext.Web.Lists.GetByTitle(listName);
var listItems = list.GetItems(GetCamlQuery(fields));
clientContext.Load(listItems);
clientContext.ExecuteQuery();
return listItems.ToList();
}
private CamlQuery GetCamlQuery(IEnumerable<string> fields)
{
var camlQuery = new CamlQuery();
var viewXml = new StringBuilder();
viewXml.AppendLine("<ViewFields>");
foreach (var field in fields)
{
viewXml.AppendFormat("<FieldRef Name='{0}' />", field).AppendLine();
}
viewXml.AppendLine("</ViewFields>");
camlQuery.ViewXml = string.Format("<View>{0}</View>", viewXml);
return camlQuery;
}
However, all of these User-fields return null, even though I'm sure some of them should contain values. What am I doing wrong?
EDIT:
- I am using the proper names: the query doesn't fail, and the
FieldValues
collection contains results for these fields, except they're allnull
. - When I use the
Display Name
, that field isn't in the result set. - I've added other fields, and they also return null, except for
"ID"
and"Title"
.
(I also just noticed I am only receiving 10 items as a result, but there are many more entries in the List I am querying. So that's another thing that is wrong...)
camlQuery.ViewFieldsOnly = true;
, just a random guess :)fields
collection. Make sure that you use valid internal names for all fields.ViewFieldsOnly
property.