views:

184

answers:

3

Hi,

I have added a resourcefile named language.resx to my App_GlobalResources folder, which enables me to access strings like App_GlobalResoureces.Language.MyString. How do I make this dynamic? So if I have a string called ResourceID, how do I pull the correct resource from the resource file?

so far I tried this:

string s = "MyString";

System.Resources.ResourceManager = new System.Resources.ResourceManager("App_GlobalResources.Language", System.Reflection.Assembly.GetExecutingAssembly()); string lang = mngr.GetString(s);

but this is not working (it says it cannot find the namespace or something).

It has been suggested to use a database for this, but I dont want this since its just a couple of enums I want to translate.

+1  A: 

How about:

string s = "MyString";
var mngr = new System.Resources.ResourceManager("Resources.Language", 
    System.Reflection.Assembly.Load("App_GlobalResources"));
string lang = mngr.GetString(s);
Mohamed Meligy
Hi Mohamed, that could well work, I found another solution (see above) before I saw yours. Thanks.
Erik
It will be great if you post it as answer and mark it, or mark another one if achieves the same. Regards.
Mohamed Meligy
A: 

its embarassing easy. Why is this extremely simple stuff always so hard to find

The correct code is:

App_GlobalResources.Language.ResourceManager.GetString("MyString");

Erik
A: 

This is proxy code generated by Visual Studio. If you want to locate the file yourself (what I thought you meant by dynamic) you'd do it as in the code sinnpet aobe. Actually, I got this code by copying the contents of the "get" accessor of the properties geenrated for resource files :)

Mohamed Meligy