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

Forums / Developing with Sitefinity / Load GenericContent From One page on Another

Load GenericContent From One page on Another

2 posts, 0 answered
  1. Byzza
    Byzza avatar
    89 posts
    Registered:
    09 Jul 2007
    16 Nov 2011
    Link to this post
    HI,
    I'm trying to create a summary page which extracts all the genericControl controls from my pages and displays them on one page at run time.
    I've got this working fairly well, but the images are being rendered as:
    <img width="28" height="28" alt="" src="[Libraries]ee13230e-33b3-4ef0-b551-71e3896a5a67" />

    ie a libraries reference instead of the actual src.
    Am I doing something wrong in my code, or do I also have to do replaces on each img.
    I haven't  tried document links yet, but I would assume their src would come through as libraries references too.

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
    public partial class LoadPages : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string strPage = Request.QueryString["guid"];
     
            LoadPrintPage(strPage);
        }
     
     
        protected void LoadPrintPage(string strPage)
        {
            if (strPage == "" )
            {
                strPage = "85C9B1EC-6EBA-4C05-BA75-A374BD61CB46";
            }
     
            Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager();
            // get the current node of sitemap
            //Telerik.Cms.Web.CmsSiteMapNode currentNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.CurrentNode;
            // get the CmsPage represented by the current node and extract its ID
            //Telerik.Cms.ICmsPage currentPage = currentNode.CmsPage;
            //Guid currentPageId = currentPage.ID;
            //// for demonstration purposes we are going to retrieve the IPage object by passing the
            //// id of the current object to the GetPage function
            //Telerik.Cms.ICmsPage currentPage = currentNode.CmsPage;
     
            Guid currentPageId = new Guid(strPage);
            currentPageId.ToString();
            //Telerik.Cms.IPage pageFromDb = cmsManager.GetPageByAdditionalUrl("~/pages/BradHelp/SAM/introduction.aspx");
            Telerik.Cms.IPage pageFromDb = cmsManager.GetPage(currentPageId,true);
            // let's output the name of the page we have retrieved from the database
            ////Response.Write(pageFromDb.Name);
            lit.Text += "<h1>" + pageFromDb.Name + "</h1>";
     
            IList<Telerik.Cms.ICmsWebControl> pageControls = pageFromDb.Staged.Controls;// currentPage.Staged.Controls;
           // Response.Write(pageControls.Count);
            foreach (Telerik.Cms.ICmsWebControl webCtrl in pageControls)
            {
                //Response.Write("test");
                if (webCtrl.ContainerID == "Content" && webCtrl.ControlType == typeof(Telerik.Cms.Engine.WebControls.GenericContent))
                {
                    Telerik.Cms.Engine.WebControls.GenericContent gcCtrl = webCtrl.LoadControl() as Telerik.Cms.Engine.WebControls.GenericContent;
                    lit.Text += gcCtrl.Content;
                     
                }
            }
            //Guid currentPageId = pageFromDb.ID;
            IList childPages = cmsManager.GetPages(currentPageId);
            // write out the number of child pages
           //// Response.Write(childPages.Count.ToString());
            foreach (Telerik.Cms.Data.CmsPage cPages in childPages)
            {
                lit.Text += "<h2>" + cPages.MenuName + "</h2>";
                subPages(cPages.ID);
                lit.Text += "<hr class='topic' /><img src='images/Print/header.png' />";
            }
     
     
        }
     
        protected void subPages(Guid strGuiID)
        {
            Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager();
     
            Guid currentPageId = strGuiID;// new Guid(strGuiID);
            Telerik.Cms.IPage pageFromDb = cmsManager.GetPage(currentPageId);
           // lit.Text += "<h2>" + pageFromDb.Name + "</h2>";
     
            IList<Telerik.Cms.ICmsWebControl> pageControls = pageFromDb.Staged.Controls;
           //// Response.Write(pageControls.Count.ToString());
            foreach (Telerik.Cms.ICmsWebControl webCtrl in pageControls)
            {
               // lit.Text += webCtrl.Name + "ABC" + webCtrl.ContainerID + ": "+ webCtrl.ControlType.ToString() ;
     
                if (webCtrl.ContainerID == "Content" && webCtrl.ControlType == typeof(Telerik.Cms.Engine.WebControls.GenericContent))
                {
                    //lit.Text +="test2";
                    Telerik.Cms.Engine.WebControls.GenericContent gcCtrl = webCtrl.LoadControl() as Telerik.Cms.Engine.WebControls.GenericContent;
                    //lit.Text += webCtrl.LoadControl() as Telerik.Cms.Engine.WebControls.GenericContent;
                    lit.Text += "<div style='margin-left:50px'>"+ gcCtrl.Content + "</div>";
                    Response.Write(gcCtrl.Content);
                }
            }
            lit.Text += "<hr />";
            IList childPages = cmsManager.GetPages(currentPageId);
            //Response.Write(childPages.Count.ToString());
            foreach (Telerik.Cms.Data.CmsPage cPages in childPages)
            {
                lit.Text += "<h3>" + cPages.MenuName + "</h3>";
                subPages(cPages.ID);
            }
        }
     
     
    }

  2. Byzza
    Byzza avatar
    89 posts
    Registered:
    09 Jul 2007
    16 Nov 2011
    Link to this post
    It looks like I have fixed it.

    It appears you need to use the rendercontrol instead of content

    ie:
    StringWriter stringWriter = new StringWriter();
                    HtmlTextWriter writer = new HtmlTextWriter(stringWriter);
                    gcCtrl.RenderControl(writer);
                    lit.Text += "<div style='margin-left:50px'>" + stringWriter.ToString() + "</div>";

    instead of :
    lit.Text += "<div style='margin-left:50px'>" + gcCtrl.content() + "</div>";


    Please let me know if there is anythign else I need to change
2 posts, 0 answered