Anders G. Nordby

Lead Consultant at Itera

Monthly Archives: May 2012

Getting all options for an EPiServer.SpecializedProperties.PropertyCheckBoxList from code

The addition of the EPiServer.SpecializedProperties.PropertyCheckBoxList (and its sister EPiServer.SpecializedProperties.PropertyDropDownList) in CMS 6 R2 was really nice.
Today I needed to list out all possitble options from code.

I had a look at these articles:

So I worte the following code:

public static Dictionary<string, string> GetCheckBoxListSettings(PageData pageData, string propertyName)
    var retval = new Dictionary<string,string>();

    if (pageData.Property[propertyName].GetType() == typeof(PropertyCheckBoxList))
        var listProp = (PropertyCheckBoxList)pageData.Property[propertyName];
        var propRepository = new PropertySettingsRepository();

        PropertySettingsContainer container;
        if (propRepository.TryGetContainer(listProp.SettingsID, out container))
            var multiSelectSettings =
                    .Where(value => value.PropertySettings.GetType() == typeof (MultipleOptionsListSettings))

            if (multiSelectSettings != null)
                var settings = ((MultipleOptionsListSettings)multiSelectSettings.PropertySettings);
                retval = settings.ListOptions;

    return retval;

Yes, I know this was simple; this blogpost is mostly a note to self.