1

Hi Guys i'm trying to retrieve a specific item from a SharePoint list using CSOM. I can get the item but im not sure how to specify multiple fields.

var Web = context.Web;
                    var SiteInfoList = Web.Lists.GetByTitle(TitleListSiteInfo);
                    var SiteInfoItem = SiteInfoList.GetItems(CamlQuery.CreateAllItemsQuery())[0];
                    context.Load(SiteInfoItem, item => item[FieldName]);

                    context.ExecuteQuery();
1
  • Try context.Load(SiteInfoItem, item => item[FieldName1], item => item[FieldName2], item => item[FieldName3]); Commented Mar 2, 2016 at 13:11

2 Answers 2

4

Try the below code, which is used to retrive the multiple field values

var Web = context.Web;
var SiteInfoList = Web.Lists.GetByTitle(TitleListSiteInfo);
var SiteInfoItem = SiteInfoList.GetItems(CamlQuery.CreateAllItemsQuery())[0];
context.Load(SiteInfoItem, item => item[FieldName],item => item[FieldName2], item => item[FieldName3]);
context.ExecuteQuery();

To get the properties of single item:

context.Load(singleitem, item => item[FieldName],item => item[FieldName2], item => item[FieldName3]);

To get the properties for collection of items:

context.Load(itemcollections, singleitem => singleitem.Include(item => item[FieldName],item => item[FieldName2], item => item[FieldName3]));
0

A better and faster approach would be to use CAML query to get specific items with specific fields. You can follow the below article to achieve that.

Generic way to use CAML query

You can specify the column in the Caml query by doing:

query.ViewXml = "<View>"
                           + "<ViewFields>"
                           + "  <FieldRef Name='" + fieldName + "' />"
                           + "</ViewFields>"
                           + "</View>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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