简体   繁体   中英

Readout XML-file from local VS2013 project (but not from harddrive-directory)

I have to readout an XML-file (with already existing content) from my local Visual Studio 2013 project structure, but not from harddrive-directory (as mentioned in the most tutorials/ guides, I've read in the last 2 hours...). After the readout process, I have to search for some tag-names in it.

I have to do this way, because the requirement is, that the specified local XML-file shouldn't appear after the build process in output directory...

So how can I do that?

See this article .

In short:

// using System.Reflection, System.IO, System.Xml

var asm = Assembly.GetExecutingAssembly();
var textStream = asm.GetManifestResourceStream('resoucename.xml');
var xmlReader = new XmlReader(textStream);
...

To add a resource, go to it's properties and change the Build Action to Embedded Resource and Copy to output directory to Never .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM