App.Config file in c # console application


I have a console application in which I want to write a file name.

Process.Start("blah.bat"); 

Normally, I would have 'blah.bat' something like this in a Windows application by writing the file name 'blah.bat' to the Settings file in Properties .
However, I did not find any settings file here and added app.config for the same purpose.

I'm not sure what to write here in app.config , which would lead me to achieve the same as in Windows Forms .

For example: in form windows. Process.Start(Properties.Settings.Default.BatchFile);
where BatchFile is a line in the settings file in Properties.

+78
c # console
Apr 09 2018-12-12T00:
source share
3 answers

You can add a link to System.Configuration in your project, and then:

using System.Configuration;

then

string sValue = ConfigurationManager.AppSettings["BatchFile"];

with the app.config file as follows:

 <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="BatchFile" value="blah.bat" /> </appSettings> </configuration> 
+166
Apr 09 2018-12-12T00:
source share

use this

 System.Configuration.ConfigurationSettings.AppSettings.Get("Keyname") 
+1
Dec 22 '15 at 6:01
source share

For .NET Core, add System.Configuration.ConfigurationManager from NuGet Manager.
And read appSetting from App.config

 <appSettings> <add key="appSetting1" value="1000" /> </appSettings> 

Add System.Configuration.ConfigurationManager from NuGet Manager

enter image description here

 ConfigurationManager.AppSettings.Get("appSetting1") 
0
Jan 01 '19 at 12:04
source share



All Articles