Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read Value from Resource file using String

I have an enum with some data on it, also I have a resource file with the same data of the enum but using different translation

Ex.

enum test
{
    Sun =1,
    Mon = 2
}

The resource file : Text.resx

Sun --> Sunday
Mon --> Monday

Now I want to get the value from the resource file but not using

string data = Resources.Text.Sun; 

but using my enum value , I have found some code but I have an exception, the code is following :

string resourceFile = "~/App_GlobalResources/Text.resx";
string filePath = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager(resourceFile, filePath, null);
string resourceValue = resourceManager.GetString(myEnum.ToString());

and I got the following Exception

Could not find any resources appropriate for the specified culture (or the neutral culture) on disk. baseName: ~/App_GlobalResources/Text.resx locationInfo: fileName: ~/App_GlobalResources/Text.resx.resources

please help as soon as you can

Thanks in Advance

like image 628
Amira Elsayed Ismail Avatar asked Oct 04 '11 07:10

Amira Elsayed Ismail


1 Answers

The resource is probably be a part of your assembly. Why don't you use the following? Resources.ResourceManager.GetString(test.Sun.ToString())

like image 90
evpo Avatar answered Oct 20 '22 20:10

evpo