Try our conversational search powered by Generative AI!

Fetch the start page for all available languages of a site?

I'm currently building a Google Sitemap generator for a site I'm developing in EPiServer 4.61, and have a small question... I want to recursively retrieve all pages in all languages enabled on the site. Not all pages have versions in all the languages, some might exist only on the English version, some only on the English version, and some might be translated on both versions. Friendly URLs are enabled on the site. Would the following code work for retrieving the start page for each language? "context" is the HttpContext, and builder is a StringBuilder I use to build the generated XML. GeneratedUrl() recursively fetches all pages using the LanguageSelector created in the foreach() loop. LanguageBranchCollection languageBranches = LanguageBranch.List(true); foreach (LanguageBranch branch in languageBranches) { LanguageSelector selector = new LanguageSelector(branch.LanguageID); PageData pdStartPage = EPiServer.Global.EPDataFactory.GetPage(EPiServer.Global.EPConfig.StartPage, selector); builder.Append(GenerateUrl(context, pdStartPage, selector)); } Everything works, except that the LinkURL of the PageData object returned on the 2nd line of the foreach() loop above links to the wrong language version of the site. If branch.LanguageID == "SV", then pdStartPage.LinkURL == "/en/", though pdStartPage.LanguageBranch == "SV" and pdStartPage.PageName contains the Swedish name for the page. Is there another method I should use for switching languages when looping through the pages of a site? Regards, /Patrik
Aug 14, 2006 19:17
Hmm, I think I should've read through the post before posting :) To clarify, some pages might exist only on the English version, some only on the Swedish, etc. /Patrik
Aug 14, 2006 19:20
Hi, Have you tried using method PageData.DetermineAutomaticURL instead of LinkURL? If That doesn't work, try using Global.EPDataFactory.GetLanguageBranches(Configuration.StartPage) for retrieving language branches for the page, instead plain GetPage().
Aug 15, 2006 9:04
That works, thanks! Though I don't understand why I have to do this, if I fetch the Swedish version of a page, shouldn't all properties on the page reflect the Swedish version?
Aug 15, 2006 9:26
Well, that's a question for EP guys... We had the same problem, I tried this and that and managed to get the right URL that way. It seems that no matter that you have the right revision of the page, its PageLink property still uses language of CurrentPage for evaluating the URL... Beats me.
Aug 15, 2006 10:41
I guess it's another one of those things we just have to accept. :) Anyway, thanks a lot for your help! Now my Google Sitemap generator works. /Patrik
Aug 15, 2006 11:13
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.