Re: Resource files in ASP.net

  • Thread starter Thread starter SamIAm
  • Start date Start date
S

SamIAm

Hi Ash

Try the following:
1) Create a folder called ResourceFiles
2) Right click on the new folder and add a new resources file called
appResource.resx (Very NB: Default - If no culture is found)
3) Open the resource file and add a key Hello with value Hello
4) Repeat step 2 and name the new resource file appResources.en-AU.resx
(English - Australia)
5) Add a key Hello with a value Gday Mate
6) Create a new webform and add the following:
using System.Resources;
using System.Reflection;
using System.Threading;
using System.Globalization;

In the Page_Load event add:
String SelectedCulture = "en-AU";
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(SelectedCulture);
Thread.CurrentThread.CurrentUICulture =
Thread.CurrentThread.CurrentCulture;

Assembly a = Assembly.GetExecutingAssembly();
ResourceManager rm = new
ResourceManager("MyWebApp.ResourceFiles.appResource", a);

lblHello.Text = rm.GetString("Hello");

That should get you going!

S
 
Back
Top