使用String从资源文件读取值

我有一个包含一些数据的枚举,我也有一个资源文件,其中包含相同的枚举数据但使用不同的翻译

防爆。

enum test { Sun =1, Mon = 2 } The resource file : Text.resx Sun --> Sunday Mon --> Monday 

现在我想从资源文件中获取值但不使用

 string data = Resources.Text.Sun; 

但是使用我的枚举值,我找到了一些代码,但我有一个例外,代码如下:

 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()); 

我得到以下例外

找不到适合磁盘上指定文化(或中性文化)的任何资源。 baseName:〜/ App_GlobalResources / Text.resx locationInfo:fileName:〜/ App_GlobalResources / Text.resx.resources

请尽快帮忙

提前致谢

资源可能是您的程序集的一部分。 你为什么不使用以下? Resources.ResourceManager.GetString(test.Sun.ToString())

如果您使用的是本地资源,并且资源项的名称是Sun,则可以编写以下内容

 GetLocalResourceObject("Sun").ToString(); 

编辑:不要忘记将资源文件命名为ur网页文件名并使用App_LocalResources :EX:网页是Test.aspx ,然后你的资源文件是Test.aspx.resx