5

I want to load all FieldValues for a specific ListItem

ForExample

  public ListItem GetItemById(List SPList, int id, string[] fieldNames)
        {
            using (Ctx)
            {
                ListItem item = SPList.GetItemById(id);
                if (fieldNames != null)
                {
                    foreach (string field in fieldNames)
                    {
                        Ctx.Load(item, i => i[field]);
                    }                   
                } 
                //Tried below line, doesn't work
                //Ctx.Load(item, i => i.FieldValues);            
                Ctx.ExecuteQuery();
                return item;
            }

So in above example i am passing the field names to load, however i want all fields to be loaded.

2

According to my research, List.GetItemById will naturally return all the fields of the item as well as their values, while other methods of getting a list item will not.

For example: List.GetItemById Will Return Item with All Fields

  • No it doesn't load all values – Kunal Valecha Jul 1 '16 at 12:07
2

None of the existing answers worked for me. This does:

CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = string.Format("<View Scope=\"RecursiveAll\"><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Number'>{0}</Value></Eq></Where></Query></View>", itemId);
ListItemCollection collListItem = list.GetItems(camlQuery);
clientContext.Load(collListItem);
clientContext.Load(collListItem,
      items => items.Include(
          item => item.Id,
          item => item.DisplayName,
          item => item.HasUniqueRoleAssignments,
          item => item.Folder,
          item => item.File,
          item => item.ContentType
          ));
clientContext.ExecuteQuery();

...

0

try this

var item = list.GetItemById(id);
                _context.Load(item);
            _context.ExecuteQuery();
  • No field values are loaded this way. – Shai Petel Aug 2 at 16:30
-1

One should try following code

var item = list.GetItemById(id);
spContext.Load(item);
spContext.Load(item.Fields);
spContext.ExecuteQuery();

This will load all the fields of the given list item.

  • 2
    It seems that a list item in this context does not have a Fields collection so it can't be loaded this way. – Colin Gardner Apr 15 '18 at 8:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.