Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

Experts,

I need to read a section of Tridion.ContentManager.config file from my Custom resolver c# code.

Any Idea How to do it?

Custom Resolving

As per the SDL Live documentation here (login required): http://sdllivecontent.sdl.com/LiveContent/content/en-US/SDL_Tridion_2011_SPONE/concept_753C261063AD4B9CA5E4F50BD4FD48E9I, I want to read value for the key “Title” for the section "My.Tridion.CustomResolving". Very similar to the example provided in the docs:

private string SCHEMA_TITLES = Config.GetConfig("My.Tridion.CustomResolving", "schemaTitles");

However, it does not really explain where the Config class comes from or how to instantiate it.

I am guessing, I will have to use class “Tridion.ContentManager.ConfigurationSettings” in the code, but not really sure.

Please help.

Thanks

Saurabh

share|improve this question

2 Answers 2

up vote 7 down vote accepted

I wrote a blogpost about this exact issue: http://albertromkes.com/2014/01/20/custom-resolvers-and-configuration/

In short: you have to load the Tridion.ContentManager.config file yourself from the configuration of the calling application (TcmServiceHost, Publisher, etc).

share|improve this answer

Honestly, don't know, why do you need it (if you want save key/value pairs you can do it without Tridion configuration handlers). But if you really want it, I've made fast example. For next xml:

<My.Tridion.CustomResolving>
 <Keys>
  <add key="title"
 </Keys>
</My.Tridion.CustomResolving>

You need to have something next:

public class NameValueSectionHandler : CentralizedConfigurationSection
    {
        private const string _keyCollectionConfigurationProperty = "Keys";

        public override string Name
        {
            get
            {
                return "My.Tridion.CustomResolving";
            }
        }

        /// <summary>
        /// Gets the Keys.
        /// </summary>
        [ConfigurationProperty(_keyCollectionConfigurationProperty)]
        public KeyCollection KeyCollection
        {
            get
            {
                return (KeyCollection) this[_keyCollectionConfigurationProperty];
            }
        }
    }

 public class KeyCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new KeySettings();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((KeySettings)element).Key;
        }
    }

public class KeySettings : ConfigurationElement
    {
        private const string _keyAttributeName = "Key";
        private const string _valueAttributeName = "Value";

        [ConfigurationProperty(_keyAttributeName)]
        public string Key
        {
            get
            {
                return (string) this[_keyAttributeName];
            }
            set
            {
                this[_keyAttributeName] = value;
            }
        }

        [ConfigurationProperty(_valueAttributeName)]
        public string Value
        {
            get
            {
                return (string) this[_valueAttributeName];
            }
            set
            {
                this[_valueAttributeName] = value;
            }
        }
    }

(CentralizedConfigurationSection is from Tridion.Configuration)

Almost forgotten... After that you need do something like:

NameValueSectionHandler handler = Tridion.Configuration.ConfigurationManager.GetSection<NameValueSectionHandler>("My.Tridion.CustomResolving");

With help of this handler - you can read your configuration.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.