Krompaco

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:

Screenshot of the settings

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, RegexOptions.IgnoreCase).Success)
{
...
}

Categories: EPiServer, Development

Last update Tuesday 20 July 2010 10:03
RSS for comments to this page Trackback URL

Comments

Add Your Comment

Pages

Feeds & Copyright