[英]Read Value from Resource file using 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.