This is how to retrieve the address to the startpage including the currently active language branch (e.g. “/sv/” or “/en/”):
PageData pagedata = Global.EPDataFactory.GetPage(Global.EPConfig.StartPage); string url = pagedata.DetermineAutomaticURL(LanguageContext.Current.CurrentLanguageBranch);
This code looks simple but it actually took me an hour or so to get it right (I haven’t worked with globalization before) so I thought it’d make a good blog post…
/Emil
How to achieve it in EPiServer CMS 5?
I have unfortunately not worked with CMS 5 yet so I’m afraid I cannot help you out…
If you solve your problem, then feel free to post the solution here 🙂
Cheers,
Emil
string langCode = CurrentPage.LanguageBranch.ToString();
I’ve posted a sample of getting the start page url in EPiServer CMS 5 (or later) at http://labs.kaliko.com/2010/10/get-start-page-url-in-episerver-cms-5.html
Here’s the code:
PageData pagedata = Global.EPDataFactory.GetPage(new PageReference(EPiServer.Configuration.Settings.Instance.PageStartId));
EPiServer.UrlBuilder url = new EPiServer.UrlBuilder(pagedata.LinkURL);
EPiServer.Global.UrlRewriteProvider.ConvertToExternal(url, pagedata.PageLink, System.Text.UTF8Encoding.UTF8);