0

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.

3 Answers 3

1

How about:

string s = "MyString";
var mngr = new System.Resources.ResourceManager("Resources.Language", 
    System.Reflection.Assembly.Load("App_GlobalResources"));
string lang = mngr.GetString(s);
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Mohamed, that could well work, I found another solution (see above) before I saw yours. Thanks.
It will be great if you post it as answer and mark it, or mark another one if achieves the same. Regards.
0

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 :)

Comments

0

It's embarassing easy. Why is this extremely simple stuff always so hard to find

The correct code is:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.