Home > OS >  How to add paths in app.config file in c#?
How to add paths in app.config file in c#?

Time:10-23

How can I add File paths in app.config and then use the file path in c# Project as one of my requirements in project is not to hardcode file paths in .cs file.

enter image description here

CodePudding user response:

You can configure User-scoped and Application-scoped settings by using the properties pages of your project. More details here: enter image description here

If you haven't yet created a settings file click on the link in the middle of the page. After doing so the page should look like in the following screenshot and you should be able to create new settings:

enter image description here

In this example I created an application-scoped setting called "SomeSetting" with a value of "C:\SomeDir". This setting can later be accessed using:

var s = Settings.Default.SomeSetting;
  • Related