1

Does SharePoint expose a list that can be queried for list metadata as returned in List.Fields?

Background: My aim is to request only the data that I need. When I write:

// string listName = "My List";
var myFields = context.LoadQuery(context.Web.Lists.GetByTitle(listName).Fields);
context.ExecuteQuery();

myFields contains 74 elements. However, I am interested in only a handful of these so I want to restrict myFields to that small subset. If I know the fields, I can add a .Where(x => (x.Title == "Field1" || x.Title == "Field2" ...)), but if I did not know the fields of interest, how would I limit the fields returned?

All my efforts to do it with pure CSOM code have failed. I have come to the conclusion that I need to construct a CAML query, but I am interested in the metadata (Title and InternalName) and not the contents of "My List". Is it possible?

1

it's not possible to use CAML query to get/filter the list fields because of the list.Fields is a collection property, not a function which could accept the CAML query to filter out the fields.

  • OK, so I cannot query "My List", but is there a metadata list that I could query? For example, in an MS SQL Server database I can write: select column_name, data_type, character_maximum_length from information_schema.columns where table_name = 'My List' and column_name in ('col1', 'col2', 'col3') – Test User May 31 '17 at 13:02
  • @TestUser, no; it is not possible. – Karthik Jaganathan Jun 1 '17 at 4:43
0

It's better to have a List associated with a Content Type. So that you can have a set of Fields retrieved from the Content Type using CSOM.

please refer this link to create a list using content type.

To create/edit a content type please refer this.

  • Understood, but it is not my SharePoint site. I have to work with it as I find it. – Test User May 31 '17 at 20:07

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.