1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Retrieve Default Provider Programmatically at runtime

Retrieve Default Provider Programmatically at runtime

5 posts, 0 answered
  1. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    23 Oct 2009
    Link to this post
    How do I retrieve the name (string) of the default provider for any of the modules (for example events) at run time? I need to instantiate a contentmanager but since the default provider might change I want it to automatically retrieve the default one set in web.config.

    how is this done? thanks!
  2. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    23 Oct 2009
    Link to this post
    okay never mind I think I found it!

    var

     

    handler = (SectionHandler)ConfigurationManager.GetSection("telerik/events");

     

    mgr =

     

    new EventsManager(handler.DefaultProvider);

    SectionHandler needs to come from the desired namespace (i.e. Telerik.Events.Configuration.SectionHandler)

    let me know if I missed something!

     

     

     

  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    23 Oct 2009
    Link to this post
    Hi SelArom,

    You can use the code below as well

    //GET SINGLE PROVIDER
    string defaultProvider = NewsManager.DefaultContentProvider;
     // GET ALL CONTENT PROVIDERS
    IDictionary<string, ContentProviderBase> providers = ContentManager.Providers;
    foreach (KeyValuePair<string, ContentProviderBase> provider in providers)
    {
       string providerKey =  provider.Key.ToString();
    }


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  4. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    23 Oct 2009
    Link to this post
    thanks Ivan, I tried the first one but the compiler warned me the manager might have a null reference. I figured it'd be safe to disregard but I thought I'd ask anyway.

    am I correct in assuming that the DefaultContentProvider property does the same thing as my code?

    thanks!
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    23 Oct 2009
    Link to this post
    Hello SelArom,

    First this is a sample code and it is up to you how and where you will use it. Of course the compilator will warn you for each object which is not check whether it is null or not.

    if (!String.IsNullOrEmpty(defaultProvider))
     {
         //do something
     }

    I hope this make the thinks more clear.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
5 posts, 0 answered