Resource File (RESX) with LINQ to XML

6. April 2009 22:15

So I'm working on making an editor for ASP.NET resource files.  I know there are some out there, but with like most things it has to be custom.  Anyway I wanted to utilize this in the most efficient way, and of course the winner is LINQ to XML as far as reading out the data from the XML file.  So far I haven't got much further than this but just wanted to show how easy it was with LINQ to XML to grab the values I needed from the resource file:

  XDocument resxXML = XDocument.Load(Server.MapPath(string.Format("~/App_LocalResources/{0}", resxFile.Name)));


  var resxData = from data in resxXML.Root.Descendants("data")
                 select new
                 {
                     ResxName = data.Attribute("name").Value,
                     ResxValue = data.Element("value").Value
                 };

 

  foreach (var ele in resxData)
  {
      Response.Write(string.Format("RESXName: {0} &nbsp; &nbsp; &nbsp; &nbsp; RESXValue = {1}<br />", ele.ResxName, ele.ResxValue));
  }

resxFile.Name is a variable I have storing the file I need from the resource file directory.

So now my next task will be to edit and write the data back to the resource file.  I'll figure that one out soon and when I'm done with it all I'll put it up here for people to use as well.

Tags:

ASP.NET

blog comments powered by Disqus



My Random Thought

I think the OCW is a great thing to have available to those who are in school, just finished school or just want to educate themself

http://ocwconsortium.org/

John On Twitter

Discounts