Sitecore read a specific field under section "Data" from an Item

1.4k Views Asked by At
item.Fields.ReadAll(); 

Gives us all the fields of the item. Is there some way to get only the fields which are grouped under the Field Section "Data".
Just to elaborate a little more:

 -> Data
     - Address
     - Street
     - ZIP
 -> Extra Data
     - Phone
     - Fax

So in this case I want to get only the Fields defined under the section "Data".

1

There are 1 best solutions below

1
On BEST ANSWER

Get your template from a template ID and a database:

var template = TemplateManager.GetTemplate( item.Template.ID, Factory.GetDatabase("contentDatabaseName"));

and then

private static IEnumerable<TemplateField> GetDataFields(Template template)
 {
            var allFields = template.GetFields();
            var dataFields = allFields.Where(x => x.Section.Name == "Data");
            return dataFields;
}

now when you have the field IDs, you can get your values

var data = item.Fields[field.ID].Value;