获取.Net库中文件的路径

发布于 2024-09-26 04:55:29 字数 232 浏览 0 评论 0原文

我的库项目正在尝试从库中也包含的文件打开 XmlDocument。如何获取库中文件的路径以便打开它?

当前目录没有用,Server.MapPath 返回主 Web 应用程序 (MVC) 的路径,那么如何获取库中文件的路径呢?

- - - - 编辑 xml 文件位于库项目内的一个文件夹中,该文件夹在部署时不存在。因此,这些文件似乎需要存在于库外部的文件夹中(例如 IIS 中的虚拟目录)。

史蒂夫

My library project is trying to open an XmlDocument from a file that's also contained in the library. How do I get the path of a file in the library so I can open it?

The current directory is not useful and Server.MapPath returns me the path of the main web application (MVC), so how do I get the path of the file in the library?

------- Edit
The xml files are in a folder within the library project which wont exist when deployed. So it seems these files need to exist in a folder outside of the library (in a virtual directory in IIS for instance).

Steve

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灰色世界里的红玫瑰 2024-10-03 04:55:29

如果您正在查找当前正在执行的程序或程序集的路径(我不确定您是不是),请使用您要查找的 AssemblyLocation 属性重新感兴趣:

string path = Assembly.GetExecutingAssembly().Location;

string path = Assembly.GetAssembly(typeof(TypeInAssembly)).Location;

If you're looking for the path of the currently-executing program or assembly (I'm not sure that you are), use the Location property of the Assembly you're interested in:

string path = Assembly.GetExecutingAssembly().Location;

or

string path = Assembly.GetAssembly(typeof(TypeInAssembly)).Location;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文