我如何使用XDocument.Load()在应用程序目录中获取文件 [英] How I use XDocument.Load() to get a file in the application directory

查看:340
本文介绍了我如何使用XDocument.Load()在应用程序目录中获取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目的文件夹中有一个XML文件.我想使用XDocument.Load(string),但是我是否必须将应用程序的完整路径作为URI的一部分(例如在我的示例中)?

I have a XML file in a folder in the project. I would like to use XDocument.Load(string) but do I have to write the complete path to the application as part of the URI (such as in my example)?

XDocument xml = XDocument.Load("c:/users/myuser/documents/visual studio
2010/Projects/ErrorRegistro/Registro.xml");

推荐答案

另一种绕过资源问题的方法是将文件添加到项目中(与资源解决方案相同),然后单击文件,然后在属性选项卡中选择复制到输出路径中的始终复制".这样,文件在构建时将被复制到输出目录,就像这样做一样简单

Another way that bypass the ressource issue is to add the file to project (same as the ressource solution), then click on the file and in the property tab choose "copy always" in copy to output path. That way the file will get copied to the output directory when you build and it's as simple as doing

 XDocument xml = XDocument.Load("Registro.xml");

这篇关于我如何使用XDocument.Load()在应用程序目录中获取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆