Programmatically get a specific page

Posted by Community Admin on 04-Aug-2018 11:02

Programmatically get a specific page

All Replies

Posted by Community Admin on 08-Apr-2014 00:00

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!

Posted by Community Admin on 11-Apr-2014 00:00

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
 

Posted by Community Admin on 11-Apr-2014 00:00

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?

Posted by Community Admin on 14-Apr-2014 00:00

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
 

Posted by Community Admin on 14-Apr-2014 00:00

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: www.facebook.com/HireMobileappsDevelopers from this source you can find the best mobile app developer that help you.

This thread is closed