Click here to Skip to main content
15,889,724 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,


I have created a console application where the text file contents are being moved to a database table .I want to declare the text file path in app config can any 1 tell how to declare the text file path in app config n how to call it in a console application
Posted
Comments
[no name] 10-Aug-13 10:42am    
http://forums.asp.net/t/1168194.aspx/1

Hello there,

I think you can add the required data as Key and Values like :
Open the app.config file and add the "appsetting" node under configuration. Add the values as key and value pair

XML
<appSettings>
    <add key="Key1" value="Key1Value"/>
    <add key="Key2" value="Key2Value"/>
  </appSettings>


To get the values from the app.config you need to add the System.Configuration reffrence in your Console application.
To access the value with the help of Key :

string keyval = ConfigurationManager.AppSettings.Get("Key1");

I think this is going to serve the purpose. Do let me know if this is not what you want.

regards
 
Share this answer
 
v2
Sorry some of the part of the code you have posted was not visible but If you just want to have the path for a file in app config yes you can save either [Full Path] or [Partial path] for the file like

<appSettings>
    <add key="Key1" value="D:/data.xml"/>
    <add key="Key2" value="Key2Value"/>
  </appSettings>


and to access the value :
string keyval = ConfigurationManager.AppSettings.Get("Key1");

check if the file exists on the location or not :
bool boo = File.Exists(keyval);

You need System.IO reference in your app.

Regards
 
Share this answer
 
v2
so if i give my file path like


<appsettings>
<add key="Key1" value="" net.txt="">



is this valid?

string keyval = ConfigurationManager.AppSettings.Get("Key1");
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 11-Aug-13 1:02am    
Not an answer, should no be here. Besides, no one got a notification. Use comments for such purposes.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900