How do I get a list of pages FluentAPI - General Discussions - General Discussions - Progress Community
 General Discussions

How do I get a list of pages FluentAPI

  • How do I get a list of pages FluentAPI
  • Hi all,
    I have looked at the Fluent api but I must be missing something.
    I want to be able to get a list of all pages that are Owned by a grouping page I have called "Destinations"

    So I want to do something like: Get all child pages of page("destinations") and then I want to be bale to loop through the list and out put them.

    Can anybody help with this.

  • Hello Gary Wedekind,

    Please see the sample code below, which displays the children of Destination in a RadGrid
    Copy Code
               var pages = App.WorkWith()
                               .Where(p => p.Parent != null)
                               .Where(p => p.Parent.Title == "Destinations")
               if (pages != null && pages.Count > 0)
                   //do something
                   Grid1.DataSource = pages.ToList();

    I hope this information helps. if you need any further assistance, please do not hesitate to contact me.

    All the best,
    Boyan Barnev
    the Telerik team
  • I'm trying to do the samething to build my custom menu, instead of binding it to a grid, can they be bound to a datalist, etc.?

    I'm creating a custom nav, the one 'out of the box' just won't work for me
  • I use something similar to this:

    SiteMapProvider provider = SiteMapBase.GetSiteMapProvider("FrontEndSiteMap");
    SiteMapNode root = provider.RootNode;
    SiteMapNode current = provider.CurrentNode;

    You can then iterate over nodes and child nodes.  The SiteMapNode should cast to Telerik.Sitefinity.Web.PageSiteNode giving you access to sitefinity-specific properties so you can build your URLs and test whether a page should be included in the navigation.

  • how would you then display your pages on a usercontrol/page?
  • I created a user control then added it to my page controls in the admin area.  That gave me a widget I could drag on to my pages (Administration>settings>advanced>toolboxes>toolboxes>pagecontrols>sections>mycustomsection).  This process is fairly well documented in the SDK.  I have also found some success in customizing my CSS and templates using a navigation control.

    Hope this sends you in the right direction.
  • I have several user controls being used within the site, yeah their easy to implement into our site and for my nav that they want, the nav control won't work so I have to create it from "scratch" and I'm just having issues getting the pages
  • Cool.  Here's the code that I use to render a link:

    private void RenderLink(SiteMapNode node, int level, HtmlTextWriter writer)
        HyperLink link = new HyperLink();
        link.CssClass = "nav_link_level_" + level;
        link.ToolTip = node.Title;
        link.NavigateUrl = this.ResolveUrl(node.Url);
        this.RenderImageLink(node, link, writer);

    And the recursive caller:

    private void RenderItem(SiteMapNode node, int level, HtmlTextWriter writer, int index)
        PageSiteNode pageNode = (PageSiteNode)node;
        if (pageNode.ShowInNavigation)
            if (level < (maxDepth + 1))
                if (!String.IsNullOrEmpty(this.ItemCssClass))
                    writer.AddAttribute("class", this.ItemCssClass);
                RenderLink(node, level, writer);
                if (node.HasChildNodes && level < maxDepth)
                    if (!String.IsNullOrEmpty(this.LeafCssClass))
                        writer.AddAttribute("class", String.Format(this.LeafCssClass, index));
                    foreach (SiteMapNode child in node.ChildNodes)
                        RenderItem(child, level + 1, writer, index);
                    writer.RenderEndTag(); // ul
                    writer.RenderEndTag(); // div
                writer.RenderEndTag(); // li

    As you can see, this is a very manual approach.  I took this approach so I could build the menu No levels deep and also because I needed to use images from an image album.  I explored binding a list of SiteMapNodes to a repeater and datalist but it turned out to be easier just rendering it on my own.
  • Thanks for the answers guys,
    I am having to rebuild my Development Environment due to hardware issues, but I will report back soon and let you know how it worked out.

  • I just had to do something very similar to this and just wanted to add a couple of thoughts.

    You'll also probably want to check to make sure the page is supposed to be shown in the navigation.
    Also, I think it defaults to sorting alphabetically.  If you want to use the sitemap hierarchy you'll need an OrderBy clause.
    Lastly, there is no "Url" property like there is for title so you'll need to use the "GetFullUrl" function to create links.  Here's my code which binds to a repeat to create a simple UL list of links.

    <%@ Import Namespace="Telerik.Sitefinity.Pages.Model" %>
    <%@ Import Namespace="Telerik.Sitefinity.Modules.Pages" %>
    <asp:Repeater ID="menuAbout" runat="server">
        <ItemTemplate><li><asp:HyperLink ID="hypAbout" runat="server" NavigateUrl='<%#((PageNode)Container.DataItem).GetFullUrl() %>' Text='<%#Eval("Title") %>' /></li></ItemTemplate>

    and then the backend code:

    using Telerik.Sitefinity;
    using Telerik.Sitefinity.Pages.Model;
    using Telerik.Sitefinity.GenericContent.Model;
    using Telerik.Sitefinity.Modules.Pages;
            var pages = App.WorkWith()
                   .Where(p => p.Parent != null)
                   .Where(p => p.Parent.Title == "About Us")
                   .Where(p => p.ShowInNavigation == true)
                   .OrderBy(p => p.Ordinal)
            if (pages != null && pages.Count > 0)
                menuAbout.DataSource = pages;

    I like Sitefinity 4 a lot but am finding it WAY more complicated than 3.7 so I hope that helps someone else.

    Note:  I updated the code above to include a "LocatedIn" clause... otherwise you'll tear your hair out trying to figure out why your pages crash when you log out of Sitefinity.

    Note 2:
    "Page.Status == ContentLifecycleStatus.Live" doesn't work if you have any external links in the list.  I removed it and replaced with ".ThatArePublished()" instead and that seems to do the trick.
  • how can I do this samething in 3.7?
  • Hello Mike,

    Please check the following documentation article -
    In order to filter by any of the properties page, you should first get all pages in a list, and filter this list using foreach(), and check inside of the loop the individual object properties. 

    the Telerik team

  • Hi,

          I am using Fluent Api to get List of Pages. My code snippet is 

          var pageNodes = App.WorkWith().Pages()              .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend) .Where(p => p.GetPageData() != null && p.NodeType == Telerik.Sitefinity.Pages.Model.NodeType.Standard)  .ThatArePublished() .Get().ToList();

    I want to sort the retreive page nodes by LastModified parameter.

    Can some one help me.