Custom fields from the Sharepoint list only.

Is it possible to iterate over a collection of fields from a sharepoint list and retrieve only our custom fields, and not the built-in sharepoint fields.

using (SPSite site = new SPSite("http://localhost/")) { using (SPWeb web = site.OpenWeb()) { SPList list = web.Lists["My List"]; foreach (SPField field in list.Fields) { //We also get sharepoint built-in column here. And we don't want that, just our //custom created fields. } } } 

Any help would be appreciated.

thanks

+4
source share
3 answers

You have two options:

  • Check if the field is an inline field: SPBuiltInFieldId.Contains(field.Id)
  • Check out SPField.SourceId (from MSDN):

Gets either a namespace that defines the built-in field, or, if it is a custom field, a GUID that identifies the list or website on which it was created.

+9
source

Here's a contrived (and currently untested) way:

 string fieldTypeClass = field.FieldTypeDefinition.FieldTypeClass; if (!(string.IsNullOrEmpty(fieldTypeClass) || fieldTypeClass.StartsWith("Microsoft.SharePoint"))) { //Only custom fields here } 
0
source

I don’t know if this is really what you are looking for if LINQ is still smiling at .net digirati, but using LINQ for Sharepoint may work for you.

-2
source

Source: https://habr.com/ru/post/1344116/


All Articles