Reading a value from a resource file using String

I have an enumeration with some data about this, also I have a resource file with the same enumeration data, but using a 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 found some code, but I have an exception, the code is as follows:

 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 resources suitable for the specified culture (or neutral culture) on the disk. BASENAME: ~ / App_GlobalResources / Text.resx locationInfo: fileName: ~ / App_GlobalResources / Text.resx.resources

please help as soon as you can

Thanks at Advance

+6
source share
2 answers

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

+6
source

If you are using a local resource and the resource name is Sun, you can write the following

 GetLocalResourceObject("Sun").ToString(); 

Edited: do not forget to specify the resource file as the name of the ur web page file and use App_LocalResources : EX: web page Test.aspx , then your resource file Test.aspx.resx

-1
source

Source: https://habr.com/ru/post/898571/


All Articles