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

Forums / Developing with Sitefinity / Get all instances of a Generic Content control

Get all instances of a Generic Content control

2 posts, 0 answered
  1. Øystein Skjesol
    Øystein Skjesol avatar
    1 posts
    Registered:
    25 Sep 2005
    13 May 2009
    Link to this post
    Hi
    I have a website where the same Generic Content can be placed on more than one page.

    Now, I need to write a module that gets all Pages where this control is reused.
    More - I need to get the Parent of this page.

    In pseudo-code:
    Find all Generic Content controls on current Page
    For each control:
     - find all Pages where this control is placed
    Show a total list of these Pages.Parent, hyperlinked to it. The list should be without duplicates.

    I would like to do this without messing directly with the database, but i do not know if it is possible to do in Sitefinity API without adding a lot of SQL-requests/CPU work...

    Any ideas? 
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    13 May 2009
    Link to this post
    Hi Øystein Skjesol,

    This can be done with the API. I assure you that everything in regards to content/pages/templates can be done via API rather than SQL queries.

    You can use the following code:
     
            CmsManager manager = new CmsManager(); 
            // Get all GenericContent controls in a list  
     
            IList pages = manager.GetPages(); 
     
            foreach (IPage page in pages) 
            { 
                foreach (WebControl control in page.Controls) 
                { 
                    if (control.GetType() == (typeof(Telerik.Cms.Engine.WebControls.GenericContent))) 
                    { 
                        Telerik.Cms.Engine.WebControls.GenericContent webControlGC = control as Telerik.Cms.Engine.WebControls.GenericContent; 
                        if (webControlGC != null
                        { 
                            //The Generic Content ID of the content showed in this control is: 
                            Guid contentID = webControlGC.ContentID; 
                            Response.Write(String.Format("We are on page {0}, and the content item is {1}<br />", page.Name, contentID)); 
                        } 
                    } 
                } 
            } 

    Once you get the Generic Content instance, you can check if the control has a text in the Content property. If yes, then the control is using a non shared content. If no, then you can check the property ContentID in order to have a reference to the actual content item.

    I hope this helps.

    Sincerely yours,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
2 posts, 0 answered