如何使路径可配置?
我正在使用以下语法
XDocument config = XDocument.Load(@"path to the xml file");
,但我在 c# 代码中包含此语句。我想让路径可配置,例如 在应用程序的 web.config 文件中使用名称路径声明一个键,我应该能够在 C# 代码中获取它 通过 xdocument cofnig =xdocument.Load(path)。
这样可以吗?
I am using the following syntax
XDocument config = XDocument.Load(@"path to the xml file");
But i am inlcuding this statement in the c# code.I want to make the path configurable like
declare a key in the web.config file of the application with the name path and i should be able to get that in the c# code
by xdocument cofnig =xdocument.Load(path).
Is it possible this way ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许做通常的事情就足够了:
这假设 web.config 包含:
Perhaps it would be sufficient to do the usual:
This assumes an web.config which contains:
我假设您询问如何将键/值对放入 web.config 中,然后在代码中检索它们。请查看以下内容:
http://msdn .microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings.aspx
I'm assuming you're asking how to put a key/value pair into the web.config and later retrieve them in the code. Please take a look at the following:
http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings.aspx