More in this section

Forums / Developing with Sitefinity / Finding pages that contain a generic content module

Finding pages that contain a generic content module

4 posts, 0 answered
  1. Chip
    Chip avatar
    2 posts
    Registered:
    03 Apr 2008
    10 Jun 2008
    Link to this post

    Can I use the API to find the URLs of pages that contain a specific generic content module? I have been looking through the docs and the API via reflector and have not been able to find an obvious way to do this.

    Thanks in advance for any assistance.
  2. Paul Dain
    Paul Dain avatar
    7 posts
    Registered:
    15 Mar 2006
    11 Jun 2008
    Link to this post
    Having the same issue. Would like to determine the pages that use a given GC module -- specifically to determine the tags associated with a page.

    Any idea how we would achieve this programmatically?
  3. Chip
    Chip avatar
    2 posts
    Registered:
    03 Apr 2008
    11 Jun 2008
    Link to this post

    Below is sample code to illustrate finding tagged content using a tag ID. The next step is to use that content to find the related pages where that content may appear. I was hoping there was a collection on the content object that held related pages, but that doesn't appear to be the case.  Any ideas on how to use the API to find the pages and their URLs?

    using Telerik.Cms;  
    using Telerik.Cms.Engine;  
    using Telerik.Cms.Engine.Data;  
    using Telerik.Cms.Web;  
     
    ...  
     
     
    ContentManager manager = new ContentManager();  
    Guid g = new Guid(Request["CntTagID"].Trim());  
    ITag tag = manager.GetTag(g);  
     
    foreach (TaggedContent content in tag.TaggedContent)  
    {  
        CmsContentBase somecontent = (CmsContentBase)manager.GetContent(content.ContentID);  
          
     
        // TODO - SEARCH FOR PAGES ASSOCIATED WITH THIS PIECE OF CONTENT  
        // I was expected a collection on the content - something like somecontent.RelatedPages  
     
  4. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    20 Jun 2008
    Link to this post
    Hello Chip,

    Sorry for the late response.

    You can use CmsManager.GetControls() method to find a control of a specific type and call ICmsWebControl.GetPages() method to find all pages, which contains that control, for example:

    CmsManager manager = new CmsManager(); 
     
    IList<ICmsPage> pages = new List<ICmsPage>(); 
    foreach (ICmsWebControl control in manager.GetControls(typeof(GenericContent), false)) 
        // create a control instance 
        GenericContent gc = (GenericContent)control.LoadControl(); 
     
        // get a list of Published pages or page templates, which contains this control 
        IList<IPage> pages = control.GetPages(); 
     
        // gets the URL of the first found page 
        string url = string.Empty; 
        foreach (IPage page in pages) 
        { 
            if (page is ICmsPage) 
            { 
                url = ((ICmsPage)page).DefaultUrl.Url; 
                break
            } 
        } 
     
     
        // or get a list of Staged pages or page templates, which contains this control 
        IList<IStagedPage> stagedPages = control.GetStagedPages(); 
     

    Hope this will help.
    Please let us know if you need further assistance.

    Sincerely yours,
    Vlad
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
4 posts, 0 answered