开发者

Reading an xml / incorporating it in to a project - C#

开发者 https://www.devze.com 2023-01-30 05:45 出处:网络
if i want to add a file to a project in c#, i just right click the project, add a new xml file and then always set to copy to the output directory. That way when the user runs it there will always be

if i want to add a file to a project in c#, i just right click the project, add a new xml file and then always set to copy to the output directory. That way when the user runs it there will always be a copy of it.

Now i want to logically group 4 xml files with a folder. I added the folder, added the xml files to the folder, and set to copy. Thats great in the sense that it copies the folder to the output directory. But now however, instead of being able to open the xml file like this

XmlDocument doc = new XmlDocument();
doc.Load(filename);

i n开发者_如何学编程eed a new way of doing it as it doesnt locate the xml file as its within the folder in the output directory, opposed to directly in the output directory if that makes sense?

what can i do?

Thanks


Adding this as an answer:

doc.Load(Path.Combine("MyFolder", filename));


You could set it as an embedded resource and access it that way. Have a look at this link

http://support.microsoft.com/kb/319292

0

精彩评论

暂无评论...
验证码 换一张
取 消