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
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
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().
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?
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.