0

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?

Jaydeep
  • 1,686
  • 1
  • 16
  • 29
  • If your boss need to create separate xml file for the project just create .xml file in the application root path. If your boss need just to saving the path as a configuration setting in your project itself, just add a new value to the `web.config` file and access it like this `ConfigurationManager.AppSettings["key of the setting"]` that's it. – JayNaz Jul 26 '19 at 11:25

1 Answers1

1

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

Dawid O
  • 6,091
  • 7
  • 28
  • 36