Anders G. Nordby

Senior Systems Consultant at Making Waves AS

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 =
                (container.Settings.Values
                    .Where(value => value.PropertySettings.GetType() == typeof (MultipleOptionsListSettings))
                ).FirstOrDefault();

            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.

About these ads

One Response to Getting all options for an EPiServer.SpecializedProperties.PropertyCheckBoxList from code

  1. Anders G. Nordby 2012-08-28 at 14:32

    This works as long as the property settings are not “Set as standard” – then the SettingsID is equal to an new GUID (0000-0000-0000-0000).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: