2017-04-11 31 views

回答

0

由於resx文件只是一個xml文件的更多,你可以循環所有與XElement

string resxFile = Server.MapPath("/App_LocalResources/Default.aspx.resx"); 

foreach (XElement element in XElement.Load(resxFile).Elements("data")) 
{ 
    string currentItem = string.Format("Key: {0} Value: {1}", element.Attribute("name").Value, element.Element("value").Value); 
} 

另一種選擇的元素與ResXResourceReader。但是,您需要添加System.Windows.Forms作爲項目的參考。

using System.Resources; 

//define the filename and path for the resx file 
string resxFile = Server.MapPath("/App_LocalResources/Default.aspx.resx"); 

//load the file into the reader 
using (ResXResourceReader reader = new ResXResourceReader(resxFile)) 
{ 
    //loop all the entries 
    foreach (DictionaryEntry entry in reader) 
    { 
     string currentItem = string.Format("Key: {0} Value: {1}", entry.Key, entry.Value); 
    } 
}