Retrieving an Episerver 6 global setting value

You added some property settings to your custom property and created a couple of global settings for the editor to choose from. Then you find out you want to get hold of the setting values in code. Here's how you fetch them.

In my case it looks like this in the property global settings view in admin mode:

Admin Mode screenshot

The one I want to get the values from has the display name Avdelningar. Here's what I ended up with:

private PropertyFilteredRolesSettings GetPropertyFilteredRolesSettingsByName(string displayName)
    var p = new PropertySettingsRepository();
    var globals = p.GetGlobals(typeof(PropertyFilteredRolesSettings));

    foreach (var setting in globals)
        if (setting.DisplayName.Equals(displayName, StringComparison.OrdinalIgnoreCase))
            return ((PropertyFilteredRolesSettings) setting.PropertySettings);

    throw new Exception("Filtered Roles Settings Display Name Not Found");

// Usage example
var departmentSettings = GetPropertyFilteredRolesSettingsByName("Avdelningar");

if (Regex.Match("JustSomeRolename", departmentSettings.FilterRolesRegexPattern,

Published and tagged with these categories: Episerver, ASP.NET, Development