Search code examples
c#asp.netresource-files

Selecting resource file in code behind at runtime


Suppose I have 2 resources files; one's called HomeEN.resx and the other one is called HomeFR.resx. I've looked at online tutorials that show how the selection of the resource file is done automatically, based on the user's setting in his browser.

I want to select the resource file at runtime, something like this:

protected void Page_Load(object sender, EventArgs e)
{      
    switch (TheLanguage) {

       case 1:
            // select the English file HomeEN.resx;
            break;

       case 2:
            // select the French file HomeFR.resx;
            break;
    }
}

How do I write these statements?


Solution

  • The correct resource files are automatically read by setting the Page's Culture and UICulture properties. See the MSDN samples

    You just need to rename your files to match the expected pattern, Home.en.resx and Home.fr.resx respectively.