Reputation: 57
I have an ASP.NET Application, where I get files from an specific path. At the moment the path is a variable in my code:
string filePath = @"C:\FilesToWatch";
Now my internship boss said, that now I have to predefine the path in an .xml file. My problem is that I do not have really much experience in xml and I do not really know where to store this xml file in my project. Has anyone examples or the solution for this?
Upvotes: 0
Views: 543
Reputation: 6341
Your question is a bit unclear, but my guess is that your boss wants this as part of web.config
. It seems the natural place to put any configuration for ASP.NET MVC applications. This is so you don't need to rebuild and redeploy the whole application if this path changes. And it has XML format which you mentioned.
There are numerous ways you can set and retrieve values from the web.config
, but the appSettings
node is probably the most suited, and so you'd have something along the lines of...
<appSettings>
<add key="path" value="C:\\FilesToWatch" />
</appSettings>
You can access the variable using WebConfigurationManager
, thus:
string filePath = WebConfigurationManager.AppSettings["path"];
Further reading: Reading a key from the Web.Config using ConfigurationManager
Upvotes: 1