EPiServerMarch 1, 2012

Programmatically switching language branch in EPiServer

On the subject of “for future reference” and “note to self”, when needing to change language branch on the current context (HTTP request or in a scheduled job) in EPiServer:

EPiServer.BaseLibrary.Context.Current["EPiServer:ContentLanguage"] 
    = new CultureInfo("no");
In this case DataFactory methods such as GetPage will default to returning pages in Norwegian. These methods all have overloads with an ILanguageSelector as a parameter, but in case one for some reason don’t want to or is able to use them the above snippet seems to work well and comes in handy.