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.
Like this:
Like Loading...
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).