[C# .NET 4.0 WinForm LINQ]
I had an XML file that I added to my project as Content
, but I'm now having to make it an internal, embedded resource so it will compile with the executable and I won't have to create an install/deployment package for the app.
However, I have existing code that uses LINQ to query the XML file that won't work now that I've made the file an embedded resource. What do I need to do differently to be able to query the XML file if it's an embedded resource compared to when it's a content resource? I've seen some
Once I query the XML file, I loop through the results and load them into a list box. Here's the code I'm using to query the XML file when it's set to Content
and my loop to add to the listbox:
var computers = from e in XElement.Load(@"MyXML.xml").Elements("computer")
select (string)e.Element("name");
foreach (var c in computers)
{
if (!IsNullOrEmpty(computer))
{
lstComputer.BeginUpdate();
lstComputer.Items.Add(computer);
lstComputer.EndUpdate();
}
}
I've seen some other examples, like this one, that use the assembly to read the file into a string...is this what I would have to do? Not to further reveal my inner noob, but if that's the case, does the example in the link above return a delimited string that I can loop through so I can add the items to my listbox?
Thanks...