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

Forums / General Discussions / Iterating over Page Names

Iterating over Page Names

16 posts, 0 answered
  1. Jon
    Jon avatar
    41 posts
    Registered:
    20 Oct 2010
    29 Nov 2010
    Link to this post
    I'm trying to iterate over the page names and print the page names and their child pages as they appear on my "Page Screen" but I can't seem to find the method in the PageData Object to return all the page names. Heres my code. 

     

     

    PageManager pm = new PageManager();

     

     

     

     

    IQueryable<PageData> pd = pm.GetPageDataList();

     

     

     

     

    var tmp = pd;

     

     

     

     

    foreach (PageData pageData in tmp)

     

    {

    Response.Write(pageData.HtmlTitle.ToString());

    }

     

    The code above returns a bunch of meaningless strings...

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    29 Nov 2010
    Link to this post
    Hello Jon,

    You can use the fluent API

    var pages = App.WorkWith().Pages().Get().ToList();


    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Jon
    Jon avatar
    41 posts
    Registered:
    20 Oct 2010
    29 Nov 2010
    Link to this post
    I'm trying to iterate over it and it does not return the page names. It returns a bunch of other non-related strings. Please see code below :

     

     

    var pages = App.WorkWith().Pages().Get().ToList();

     

     

     

    foreach (PageNode pn in pages)

     

    {

        Response.Write(pn.Name);

     

    }

     

     




  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    29 Nov 2010
    Link to this post
    Hi Jon,

    Here is the code that you have to use

    // get the frontend root node name
    var root = Config.Get<PagesConfig>().FrontendRootNode;
    //get the FrontendRootNode as PageNode
    var pgs = App.WorkWith().Pages().Where(pk => pk.Name == root).Get().SingleOrDefault() as PageNode;
    // loop through all nodes are show the data.
    foreach (PageNode page1 in pgs.Nodes)
    {
        var htmlTitle = page1.Page.HtmlTitle;
        var pageTitle = page1.Page.Title;
    }

    I attached two screenshots that illustrates the pages structure.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Jon
    Jon avatar
    41 posts
    Registered:
    20 Oct 2010
    30 Nov 2010
    Link to this post
    Thanks alot for the code and screen shots however, the code below does not compile

    var

     

     

    root = Config.Get<PagesConfig>().FrontendRootNode;

     

     

     

    //get the FrontendRootNode as PageNode

     

     

     

    var pgs = App.WorkWith().Pages().Where(pk => pk.Name == root).Get().SingleOrDefault() as PageNode;

     

     

     

    // loop through all nodes are show the data.

     

     

     

    foreach (PageNode page1 in pgs.Nodes)

     

    {

     

     

    var htmlTitle = page1.Page.HtmlTitle;

     

     

     

    var pageTitle = page1.Page.Title;

     

    }

    Error : The name Config does not exist in the current context
    Error : Type or Namespace PagesConfig could not be found
    Error : The best overloaded method match for 'Telerik.Sitefinity.Fluent.Pages.PagesFacade.Where(System.Func<Telerik.Sitefinity.Pages.Model.PageNode,bool>)' has some invalid arguments

    I must be missing an assembly reference. What is the assembly I'm missing ?

    Also, I hate to ask you to write this for me but I'm confused. I need to populate a RadTree with the same 'view' as the pages screen. This means I need Parent/Child relationships in the code to make my RadTree mimic the pages screen with page names. Do you have code for this ? I would really appreciate it. The API is a little tricky so ....

     

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    30 Nov 2010
    Link to this post
    Hello Jon,

    The intelliesense should show you which reference to add when you hover on the Config helper class

    You should have the following references

    • Telerik.Sitefinity.Modules.Pages.Configuration
    • Telerik.Sitefinity.Configuration

    Just to let you know RadEditor control supports FormatCodeBlock that you can use when you paste some code.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Jon
    Jon avatar
    41 posts
    Registered:
    20 Oct 2010
    30 Nov 2010
    Link to this post
    Hi Ivan,

              I tried hovering over it and my intellisense didn't bring it up for some reason. I'm using VS 2010 too. Anyway, thanks my code compiles and I can now see all the pages except for child pages. I was wondering if you could give me the code to display child pages as well. I need to know when it's a child page too as I'm populating a RadTree with the page value names with the same hierarchy as it appears in the Pages screen. Could you supply me with the code to accomplish this?
    Regards,
    jon
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    30 Nov 2010
    Link to this post
    Hello Jon,

    You can use RadTreeView control and bind it to SiteMapDataSource. You can do this even from the UI by dropping both the controls on a page and setting SiteMapDataSource control ID to the SiteMapDataSourceID property of the RadTreeView control.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Jon
    Jon avatar
    41 posts
    Registered:
    20 Oct 2010
    30 Nov 2010
    Link to this post
    Hi Ivan,

            I still need to know how to programtically transverse Pages and child pages so I can populate my tree with Parent and Child page values. Can you give me the code for showing the child pages as well ? I need to know when its a child page so I can update my tree view with a Parent or Child value.

     Thanks in advance ,

    Jon
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    30 Nov 2010
    Link to this post
    Hi Jon,

    Each node has a Parent property and Nodes property that you can use to search recursively.

    public IList<PageNode> GetPages(Guid parentId)
           {
               IList<PageNode> listofCmsPages = new List<PageNode>();
               var manager = PageManager.GetManager();
               var allpages = manager.GetPageNodes().Where(pn =>pn.Parent.Id == parentId);
               foreach (PageNode p in allpages)
               {
                   listofCmsPages.Add(p);
                   if (p.Nodes.Count > 0)
                   {
                       foreach (PageNode nn in p.Nodes)
                       {
                           listofCmsPages.Add(nn);
                       }
                   }
               }
               return listofCmsPages;
     
           }


    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  11. Jon
    Jon avatar
    41 posts
    Registered:
    20 Oct 2010
    30 Nov 2010
    Link to this post
    Thank you so much  !
    Regards,
    jon
  12. Jon
    Jon avatar
    41 posts
    Registered:
    20 Oct 2010
    30 Nov 2010
    Link to this post
    I have tried out the function however, list.Count returns a count of ZERO even if there are child pages. I'm not sure what to do .. Please see attached code. It's pretty simple.


    var root = Config.Get<PagesConfig>().FrontendRootNode;
                //get the FrontendRootNode as PageNode
                var pgs = App.WorkWith().Pages().Where(pk => pk.Name == root).Get().SingleOrDefault() as PageNode;
                  
                // loop through all nodes are show the data.
                foreach (PageNode page1 in pgs.Nodes)
                {
                    var htmlTitle = page1.Page.HtmlTitle;
                    var pageTitle = page1.Page.Title;
                    Response.Write(page1.Page.Title);
      
                    IList<PageNode> list = GetPages(page1.Page.Id);
                    Response.Write(list.Count); // ALWAYS EQUALS ZERO EVEN IF THERE ARE CHILD PAGES
                    foreach (PageNode pages in list)
                    {
                        Response.Write(pages.Page.Title);
                    }
                }
      
             }
      
            public IList<PageNode> GetPages(Guid parentId)
           {
               IList<PageNode> listofCmsPages = new List<PageNode>();
               var manager = PageManager.GetManager();
               var allpages = manager.GetPageNodes().Where(pn =>pn.Parent.Id == parentId);
                 
               foreach(PageNode p in allpages)
               {
                   listofCmsPages.Add(p);
                   if(p.Nodes.Count > 0)
                   {
                       foreach(PageNode nn in p.Nodes)
                       {
                           listofCmsPages.Add(nn);
                       }
                   }
               }
               return listofCmsPages;
       
           }
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    30 Nov 2010
    Link to this post
    Hello Jon,

    Most probably "allpages" and enumeration that is executed there returns no. You can use VS debugger to narrow down the issue. This code returns correct values at my end.  Basically you have to properties that you have to use Parent and Nodes which will allow you to recursively get all pages and populate your control.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  14. Jon
    Jon avatar
    41 posts
    Registered:
    20 Oct 2010
    01 Dec 2010
    Link to this post
    Hi Ivan,

         I'm using the function you gave me below however, the "allpages" call is returning a count of zero for children even when there are children. I even tried hard coding my GUID like below but still the function returns zero for children when there are obviously children on my pages screen. I've looked into the debugger and can't seem to find the problem. Please help me fix this as it is vital to my project. Please see code below. I'm even hard coding the GUID and it still returns zero for a count of children. If there is a bug in the API please let me know.


    Guid gui = new Guid("18843d20-2206-497f-b2ca-e4ab0835c129");
                    IList<PageNode> list2 = GetPages(gui);
                    Response.Write("LIST2 COUNT:" + list2.Count + ":");
      
      
     public IList<PageNode> GetPages(Guid parentId)
           {
               IList<PageNode> listofCmsPages = new List<PageNode>();
               var manager = PageManager.GetManager();
               var allpages = manager.GetPageNodes().Where(pn => pn.Parent.Id == parentId);
                 
               foreach(PageNode p in allpages)
               {
                   listofCmsPages.Add(p);
                   if(p.Nodes.Count > 0)
                   {
                       foreach(PageNode nn in p.Nodes)
                       {
                           listofCmsPages.Add(nn);
                       }
                   }
               }
               return listofCmsPages;
           }
  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    02 Dec 2010
    Link to this post
    Hello Jon,

    Try using the code below. I attached a short video that shows how it works.

    public IList<PageNode> GetPages(Guid parentId)
           {
               IList<PageNode> listofCmsPages = new List<PageNode>();
               var manager = PageManager.GetManager();
               var allpages = manager.GetPageNodes().Where(pn => pn.Parent.Id == parentId);
               foreach (PageNode p in allpages)
               {
                   listofCmsPages.Add(p);
                   if (p.Nodes.Count > 0)
                   {
                       foreach (PageNode nn in p.Nodes)
                       {
                           listofCmsPages.Add(nn);
                           GetPages(p.Id);
                       }
                   }
               }
               return listofCmsPages;
     
           }


    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  16. Jon
    Jon avatar
    41 posts
    Registered:
    20 Oct 2010
    03 Dec 2010
    Link to this post
    Hi Ivan,

         Thanks it works fine now. I was passing in the Parent ID of the PageNode in wrong. I was passing in PageNode.Page.Id instead of PageNode.Id .. Anyway, it all works fine now.

    Thanks again !!

    Jon
16 posts, 0 answered