从库 dll 加载 Web 应用程序目录中的 xml

发布于 2024-09-04 03:29:10 字数 270 浏览 13 评论 0原文

我的 Web 应用程序在这里有一个 xml 文件:

/files/xml/test.xml

我需要从类库项目中加载 XDocument,我将如何引用 xml?我不想将任何路径参数传递给此方法。

我想假设位置固定在 /files/xml/test.xml

如何加载知道这一点的 XDocument?

我似乎也无法访问 server.mappath。

my web application has an xml file here:

/files/xml/test.xml

I need to load a XDocument from within a class library project, how will I reference the xml? I don't want to pass any path parameters to this method.

I want to assume the location is fixed at /files/xml/test.xml.

How can I load a XDocument know this?

I don't seem to have access to server.mappath either.

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

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

发布评论

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

评论(1

|煩躁 2024-09-11 03:29:10

你永远不应该假设地点。您的函数确实应该采用文件路径,然后从您的Web上下文中调用server.mappath来生成要加载的正确路径。

如果您想修复某些内容,请将其作为资源常量或 const 变量加载。

public static class Globals
{
   public const string TestPath = "/files/xml/text.xml";
}

You should never assume locations. Your function really should take a file path, then from your Web Context, you call server.mappath to produce the correct path to load.

If you want to fix something, load it in as a resource constant or a const variable.

public static class Globals
{
   public const string TestPath = "/files/xml/text.xml";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文