More in this section

Forums / Developing with Sitefinity / Binding CMS pages to RadMenu

Binding CMS pages to RadMenu

9 posts, 0 answered
  1. adds
    adds avatar
    8 posts
    Registered:
    10 Nov 2006
    05 Nov 2009
    Link to this post
    How can I bind a list of pages in certain folders to appear in a radmenu?

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    05 Nov 2009
    Link to this post
    Hi adds,

    1. You need to get all items from the path.
    2. Then bind the rad menu.

    sample code:

    protected void Page_Load(object sender, EventArgs e)
       {
           if (!Page.IsPostBack)
           {
               GetPage("~/Pages/");
           }
       }
       private string GetPage(string path)
       {
        string path= null;
        if (!string.IsNullOrEmpty(path))
        {
     
           DirectoryInfo directoryInfo = new DirectoryInfo(Server.MapPath(path));
           FileInfo[] fileNames = directoryInfo.GetFiles("*.aspx*");
           foreach (FileInfo fi in fileNames)
           {
              RadMenuItem item1 = new RadMenuItem();
              item.Text = fi.Name;
              RadMenu1.Items.Add(item1);         
           }
            }
       }

    The better option will be creating a simple XmlSiteMapProvider and loading the items from XML

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. adds
    adds avatar
    8 posts
    Registered:
    10 Nov 2006
    05 Nov 2009
    Link to this post
    Thanks for your reply.

    This works by looking at actual files that exist in the root (or whichever page you stipulate), however if I have pages within sitefinity these are not appearing. For example the following sitemap:

    1) Home
    1a) Clients
    1b) Testimonials
    1c) Case studies

    If I wish to pass "clients" into the GetPages function so that I can get a list of clients in that dropdown.

    Any ideas? :)
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    05 Nov 2009
    Link to this post
    Hello adds,

    The code search looks only in one level of the directory. You need to extend it to search inside the child folders or depending on the page structure you have. You can use directoryInfo.GetDirectories() which will return all sub directories of your root.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. adds
    adds avatar
    8 posts
    Registered:
    10 Nov 2006
    05 Nov 2009
    Link to this post
    I thought this code only looks for actual pages and not query the database for pages? If so, no other pages will be shown.

    When I run the code intact then I only get the default.aspx file, when in the sitefinity backend other pages exist from the root.
  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    05 Nov 2009
    Link to this post
    Hello adds,

    If you wish to bind CMS pages to the RadMenu you should bind the menu to a sitemap provider. For refference on how to do this you can take a look at the Site Menu control implementation. This is a RadMenu wrapped in a .ascx user control. You can take a look at the mark up of and code file located at ~/Sitefinity/UserControls/Navigation35/SiteMenu.ascx. It even has function to select the page from which to start.

    Best wishes,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. adds
    adds avatar
    8 posts
    Registered:
    10 Nov 2006
    05 Nov 2009
    Link to this post
    Many thanks will take a look. I am using the following code to get the pages using the API.

    How do I get the root (home) page GUID?


    Dim manager As New CmsManager() 
            Dim pages As IList = manager.GetPages(ParentGUID) 
     
            For Each page As ICmsPage In pages 
                If page.Navigable Then 
     
                    Response.Write(String.Format(vbTab & "{0} - {1}<br />", page.Title, page.Ordinal)) 
                    'Response.Write(String.Format("{0} - {1}<br />", page.Title, page.Ordinal)) 
                    Dim subItem As New RadMenuItem 
                    subItem.Text = page.MenuName 
                    subItem.NavigateUrl = "howtoget.aspx" 
                    'subItem.NavigateUrl = page.MenuName 
     
                    menuItem.Items.Add(subItem) 
     
                End If 
            Next 
     

  8. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    05 Nov 2009
    Link to this post
    Hi adds,

    The root page in the SiteMap has ID of only 0s, if you mean the most top level page in Sitefinity. The home page is something different. Here is how you get the ID of the home page, it does not matter if you change the home page it will always return the ID of the homepage.
    Dim homePageID As Guid = UrlHelper.HomePage.ID

    Sincerely yours,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. adds
    adds avatar
    8 posts
    Registered:
    10 Nov 2006
    05 Nov 2009
    Link to this post
    Perfect... thank you so much for your help. This is now working a treat!!!!
Register for webinar
9 posts, 0 answered