从库 dll 加载 Web 应用程序目录中的 xml
我的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你永远不应该假设地点。您的函数确实应该采用文件路径,然后从您的Web上下文中调用
server.mappath
来生成要加载的正确路径。如果您想修复某些内容,请将其作为资源常量或 const 变量加载。
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.