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 开发者_StackOverflow社区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 ?
Perhaps it would be sufficient to do the usual:
const string key="xmlPath";
...
string path = ConfigurationManager.AppSettings[key];
XDocument config = XDocument.Load(path);
This assumes an web.config which contains:
<appSettings>
<add key="xmlPath" value="c:\path\to\xml\file.xml" />
</appSettings>
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
精彩评论