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

Forums / Developing with Sitefinity / Programmatically get a specific page

Programmatically get a specific page

5 posts, 0 answered
  1. Luca
    Luca avatar
    1 posts
    Registered:
    17 Dec 2013
    08 Apr 2014
    Link to this post

    Hello,
    how can I programmatically get a "specific" page in my website?

    Suppose that I have the "Events" page and I would like to programmatically get it. I have seen various ways to achieve this (in the documentation and in blog posts) but none of them are suitable for me:

    • Find the page by Title
      This is not possible in a multilanguage site! The title will only work for a specific language
    • Find the page by Guid
      This is not very clean since I should hard-code the guid into my code. Moreover, where can I find a specific page guid (apart from looking into the database)?
    • Find the current page
      Again, this is not suitable because I don't want the current page, I want a "specific" page
    • Other?

    Thank you!

  2. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    08 Dec 2016
    11 Apr 2014
    Link to this post
    Hi Luca,

    You can get a specific page by its Title and then filter for the culture
    var ci = System.Globalization.CultureInfo.GetCultureInfo("en");
     
     var pageNodes = App.WorkWith()
                   .Pages()
                   .LocatedIn(PageLocation.Frontend)
                   .Where(p => p.Page.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && p.Title.Contains("Home"))
                   .Get()
                   .AsQueryable();
     
     
                var filteredTranslations = PageHelper.FilterPagesForLanguage(pageNodes, ci).AsQueryable();

    This way you get the pages starting with Home and then find the one with the specific language.
    You can do the same but querying the pageNodes by UrlName, for instance.

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Emanuele
    Emanuele avatar
    2 posts
    Registered:
    17 Dec 2013
    11 Apr 2014
    Link to this post
    Sorry but it's not an acceptable solution. Think to have a MultiLanguage site with 5 languages, a news list and a news detail. Now in news detail i need a link "All news". How can i get the url of that page knowing the title is "All news?
  4. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    08 Dec 2016
    14 Apr 2014
    Link to this post
    Hello,

    If you know the title of the page you can simple query it and get the specified language url of the page.
    Example:
                PageManager manager = new PageManager();
                var page = manager.GetPageNodes().Where(n => n.Title == "All News").SingleOrDefault();
     
                var culture = System.Threading.Thread.CurrentThread.CurrentUICulture;
     
                string url = string.Empty;
     
    if (page != null)
    {
                if (page.AvailableCultures.Contains(culture))
                {
                    url = page.GetUrl("", culture, true);
                }
                else
                {
                    url = page.GetUrl();
                }
    }
                return url;

    Note that it returns the relative url. I hope you find this helpful.

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  5. Lerman
    Lerman avatar
    1 posts
    Registered:
    14 Apr 2014
    14 Apr 2014
    Link to this post
    Nice steps shared on this post that help users to get a specific page using programmatically. There are so many sources available that useful to get specific page but as per good source concern i would like to recommend one please check it here: https://www.facebook.com/HireMobileappsDevelopers from this source you can find the best mobile app developer that help you.
5 posts, 0 answered