I have an *.xml file that I have added to my solution and set it's build action to "Resource". I want to load its contents into a List<string>
.
I found out I can access the file with ResourceManager
(after numerous tries I concluded it's impossible to access it in another way).
But XDocument.Load
requires an Uri, which I have no idea what it is for my file, because it doesn't work with what I've read on other questions and MSDN.
Here is a picture of my solution structure, pertaining to the file:
(I need "ServerList.xml")
I tried using the following Uris:
- ServerList.xml
- \ServerList.xml
- Data\ServerList.xml
- \Data\ServerList.xml
- /ServerList.xml
- Data/ServerList.xml
- /Data/ServerList.xml
None of them work.
This code, does, somewhat:
var rm = new ResourceManager("SQLExecutor.g", Assembly.GetExecutingAssembly());
var rset = rm.GetResourceSet(CultureInfo.InvariantCulture, true, true);
var obj = SerializeToStream rset.GetObject(@"data/serverlist.xml", true);
So, now, obj
is an object but I need either an Uri or a Stream to pass to XDocument.Load
. I actually just need to get the information out of the *.xml and am only using XDocument, because I think it would be best, but am having problems serializing obj
.
So what, exactly, should I do in order to be able to load this "ServerList.xml" file in an XDocument, so I can work with it?