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

Forums / Developing with Sitefinity / Access SiteFinity API for site pages

Access SiteFinity API for site pages

11 posts, 0 answered
  1. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    08 Oct 2008
    Link to this post
    I want to build my own menu control.

    I need to know if there is a way to access the SiteFinity page data (like the site menu control does now)

    Thanks,

    Nugs
  2. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    09 Oct 2008
    Link to this post
    Hey Nugs,

    I believe what you're looking for is the SiteMap:

    http://msdn.microsoft.com/en-us/library/system.web.sitemap.aspx

    This is an ASP.NET feature that Sitefinity makes use of.  The Sitefinity page structure is automatically loaded into an ASP.NET SiteMap.  You can then use this SiteMap to create your own navigation controls.

    Let me know if this doesn't help.

    Gabe Sumner

  3. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    09 Oct 2008
    Link to this post
    Hi Duncan,

    Here is an example that illustrates how to implement a simple menu:

    .ascx
    <asp:Repeater ID="menu" runat="server"
        <HeaderTemplate> 
            <ul> 
        </HeaderTemplate> 
        <ItemTemplate> 
            <li><a ID="menuItem" runat="server" href='<%#Eval("Url") %>'><%#Eval("Title") %></a></li> 
        </ItemTemplate> 
        <FooterTemplate> 
            </ul> 
        </FooterTemplate> 
    </asp:Repeater> 

    .ascx.cs
    protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!IsPostBack) 
            { 
                // get all child nodes of the root 
                SiteMapNodeCollection source = SiteMap.RootNode.ChildNodes; 
     
                this.menu.DataSource = source; 
                this.menu.DataBind(); 
            } 
        } 

    Do let us know if you need any further assistance.

    Regards,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  4. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    09 Oct 2008
    Link to this post
    thanks everyone for your comments,

    Pepi, what you posted is what i was looking for. Totally my fault, i should have been a little more clear.

    Specifically i was looking for the datasource for the SiteFinity Page Collection

    SiteMapNodeCollection source = SiteMap.RootNode.ChildNodes;

    Pepi, could you tell me what shouldbe refferenced to access this and possibly point me the the Deve Manul API reference to this class?

    Thanks,

    Nugs



  5. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    09 Oct 2008
    Link to this post
    Hello Nugs,

    Here is an example how to get all cms pages:

    CmsManager manager = new CmsManager(); 
    IList pages = manager.GetPages(); 

    For details refer to the following topics of the Developer Manual:
    Working with Pages Programmatically
    Pages API Overview

    Please explain in details if there is some misunderstanding.

    Best wishes,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    09 Oct 2008
    Link to this post
    Yup, this is what i needed... Basically my senario is that in a integrating a site that has a pre-defined top level on pages. All other pages created will/must fall under one of these top level "sections" of the site... I needed access to the page list to generate the sub menu's for each fo the sections of the site...

    this should do it but i might be revisiting this questions with some more detail when i begin working with this class...

    Thanks again,

    Nugs
  7. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    10 Oct 2008
    Link to this post
    Hello Nugs,

    Y
    ou could use Group page feature to represent the top level "sections" of the site. Then you could filter the pages by their type like this:

    .ascx
    <asp:Repeater ID="menu" runat="server"
        <HeaderTemplate> 
            <ul> 
        </HeaderTemplate> 
        <ItemTemplate> 
            <li><a ID="menuItem" runat="server" href='<%#Eval("StaticUrl")%>'><%#Eval("MenuName") %></a></li> 
        </ItemTemplate> 
        <FooterTemplate> 
            </ul> 
        </FooterTemplate> 
    </asp:Repeater> 

    .ascx.cs
    protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!IsPostBack) 
            { 
                menu.DataSource = GetSource(); 
                menu.DataBind(); 
            } 
        } 
     
        private IList<ICmsPage> GetSource() 
        { 
            CmsManager manager = new CmsManager(); 
            IList pages = manager.GetPages(); 
            IList<ICmsPage> source = new List<ICmsPage>(); 
     
            for (int i = 0; i < pages.Count; i++) 
            { 
                // Gets the current page    
                ICmsPage currentPage = (ICmsPage)pages[i]; 
     
                if (currentPage.PageType == CmsPageType.Group
                { 
                    source.Add(currentPage); 
                } 
            } 
     
            return source; 
        } 

    Hope this helps.

    Regards,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    14 Oct 2008
    Link to this post
    This is good stuff... I have started to work onmy custom menu control... One question.

    The order of the pages seems to be coming back different from order setup in SiteFinity... Is there some way to order the IList according to this?

    Nugs
  9. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    15 Oct 2008
    Link to this post
    Hi Nugs,

    You need to use the following overload of GetPages method in order to sort the list of pages:

    public IList GetPages(  
       int from, 
       int maxRows, 
       string sortExpr, 
       ListSortDirection sortDirection, 
       out int totalRows 

    For example:

    .ascx.cs
    private IList<ICmsPage> GetSource() 
        { 
            CmsManager manager = new CmsManager(); 
            int totalRows = 0; 
            IList pages = manager.GetPages(0, int.MaxValue, "DateModified", ListSortDirection.Descending, out totalRows); 
     
            IList<ICmsPage> source = new List<ICmsPage>(); 
     
            foreach (CmsPageInfo page in pages) 
            { 
                ICmsPage currentPage = page.CmsPage; 
     
                if (currentPage.PageType == CmsPageType.Group) 
                { 
                    source.Add(currentPage); 
                } 
            } 
     
            return source; 
        } 

    Hope this helps.

    All the best,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  10. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    15 Oct 2008
    Link to this post
    Pepi,

    I did try this but i have something wrong... I am trying to sort by the Ordinal... Is this correct?

    IList pages = manager.GetPages(0, int.MaxValue, "Ordinal", ListSortDirection.Descending, out totalRows); 

    Nugs


  11. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    16 Oct 2008
    Link to this post
    Hi Nugs,

    For details please refer to the forum thread you opened on the same topic: Sort the IList output from CmsManager.GetPages()

    Best wishes,
    Pepi
    the Telerik team

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