December 9, 2015

Get sitecore field details section wise

Dictionary<string, string> FieldsDetailsWithInSection = GetFieldDetailsWithInSection(<ItemID>, <SectionName>);


public Dictionary<string, string> GetFieldDetailsWithInSection(string itemId, string sectionName)
        {
            Dictionary<string, string> FieldsWithInSection = new Dictionary<string, string>();
            if (Sitecore.Data.ID.IsID(itemId))
            {
                Item item = Sitecore.Context.Database.GetItem(Sitecore.Data.ID.Parse(itemId));
                if (item != null)
                {
                    FieldsWithInSection = item.Fields.Where(name => name.Section == sectionName).OrderBy(x => x.Sortorder).ToDictionary(field => field.Name, field => field.Value);
                }
            }
            return FieldsWithInSection;
        }

That's It.
Enjoy Learning

No comments:

Post a Comment