0
我有以下靜態類用於本地化我的mvc應用程序中的字符串。 我的資源字符串存儲文件夾內像從資源文件中獲取字符串
- 資源/ EnglishStrings.resx
- 資源/ DeutschStrings.resx
public static string ReadResourceValue(string lang, string key)
{
string file = "";
if (lang == "en")
{
file = "LocalizedUIStrings.en-EN.resx";
}
else if (lang == "de")
{
file = "LocalizedUIStrings.de-DE.resx";
}
//value for our return value
string resourceValue = string.Empty;
try
{
// specify your resource file name
string resourceFile = file;
// get the path of your file
//string filePath = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
string filePath = @"~/Resources/";
// create a resource manager for reading from
//the resx file
ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager(resourceFile, filePath, null);
// retrieve the value of the specified key
resourceValue = resourceManager.GetString(key);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
resourceValue = string.Empty;
}
return resourceValue;
}
}
這樣string filePath = @"~/Resources/";
我不能與資源字符串訪問我的文件夾, 我怎樣才能做到這一點?