More in this section

Forums / Developing with Sitefinity / View a list of pages a piece of shared content is being used on?

View a list of pages a piece of shared content is being used on?

2 posts, 0 answered
  1. Zeke
    Zeke avatar
    4 posts
    Registered:
    03 Oct 2008
    04 Feb 2009
    Link to this post
    Hi,

    Is there anything built-in within SiteFinity that one could use to see a list of pages a specific bit of shared content is being used on? If not, has something been previously built for a similar request in the past or is it achievable using the SiteFinity API?

    Thanks
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    06 Feb 2009
    Link to this post
    Hello,

    This is an interesting task.

    Here is how to get all pages on which there is a Generic Content Control. The Generic Content Control itself is showing a shared content item:
    CmsManager manager = new CmsManager(); 
            // get all Generic Content Controls 
            IList controls = manager.GetControls(typeof(Telerik.Cms.Engine.WebControls.GenericContent).FullName, false); 
            foreach (ICmsWebControl ctrl in controls) 
            { 
                Telerik.Cms.Engine.WebControls.GenericContent webControl = ctrl.LoadControl(thisas Telerik.Cms.Engine.WebControls.GenericContent; 
                //for each control, check if there is ContentID set. 
                //If there is, then the Generic Content control is using Shared content 
                //otherwise, we get the "branched" content by webControl.Content; 
                //ContentID is the ID of the Generic Content Item. 
                if (webControl != null && webControl.ContentID != null
                { 
                    //so the control is using "Shared Content". Let's find the page 
                    //on which the control is placed 
                    IList<IPage> pages = ctrl.GetPages(); 
                    foreach (IPage page in pages) 
                    { 
                        //The last thing, is to do *something* with the page we found. 
                        Response.Write(String.Format("Shared content is used on {0} page <br />", page.Name)); 
                        
                    } 
                } 
            } 

    By having the ContentID, you can take any information you would like to know about the shared content item used. Just use the ContentManager like this:
    ContentManager m = new ContentManager(); 
    IContent item = m.GetContent(ContentId); 
    string title = item.GetMetaData("Title").ToString(); 

    I hope this helps. Let me know if you need any further help.

    Kind regards,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
2 posts, 0 answered