0
我需要保存在「App_LocalResources」下的當前頁面的ResX文件。如何在App_LocalResources下加載Resx文件以遍歷它
我需要遍歷它。
方法「GetLocalResourceObject」只允許當時訪問一個鍵。
我需要保存在「App_LocalResources」下的當前頁面的ResX文件。如何在App_LocalResources下加載Resx文件以遍歷它
我需要遍歷它。
方法「GetLocalResourceObject」只允許當時訪問一個鍵。
由於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);
}
}