2011-05-10 45 views

回答

-1

在cs文件鍵入您的本地化命名空間:

Localization.Resources.KeyName 

方便快捷:)

+0

你從哪裏得到本地化對象? – Muflix 2015-11-19 11:52:07

8
public string ReadResourceValue(string file, string key) 

{ 

    string resourceValue = string.Empty; 
    try 
    { 

     string resourceFile = file; 

     string filePath = System.AppDomain.CurrentDomain.BaseDirectory.ToString(); 

     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; 
} 
3

還有一個更簡單的方法:Namespace.Properties.Resources.FileName - >得到文件內容的字符串。

即:TestProject1.Properties.Resources.MyXmlFile - >直接訪問文件中的資源

-1

你可以從global resourcekeyvalue這裏。

//TestResource is resource class name. 

String keyValue=string.Empty; 

keyValue= Resources.TestResource.KeyString;