Answered by:
Read / Write App.Config

Question
-
hi how can read/ wrtie access the app.config file, using C#.net,
e.g i used to read app.config file connectstring, and i need to write[updated] the connectionstring using c#.net,
any sample of code is available please leave ur suggestion
kind regards
syed
Friday, December 7, 2007 7:26 AM
Answers
-
Hi, Syed,
Based on my understanding, you want to know how to read and write your config file, don't you?
To read the settings is quite easy.
Suppose you have a ConnectionString named "connStr".
Then you can get it like this.
Code BlockConfigurationManager.ConnectionStrings["connStr"].ConnectionString
To write the value to the config file, you will need a Configuration object.
For example,
Code BlockConfiguration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings["connStr"].ConnectionString = "New Value";
config.Save();
More info
http://msdn2.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx
Hope this helps,
Regards
Tuesday, December 11, 2007 7:12 AM
All replies
-
Hi, Syed,
Based on my understanding, you want to know how to read and write your config file, don't you?
To read the settings is quite easy.
Suppose you have a ConnectionString named "connStr".
Then you can get it like this.
Code BlockConfigurationManager.ConnectionStrings["connStr"].ConnectionString
To write the value to the config file, you will need a Configuration object.
For example,
Code BlockConfiguration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings["connStr"].ConnectionString = "New Value";
config.Save();
More info
http://msdn2.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx
Hope this helps,
Regards
Tuesday, December 11, 2007 7:12 AM -
It gives the error message "Object Refrenecs not set to the instance of object"
Please Help me
thanksWednesday, July 16, 2008 2:57 AM -
try
string MyConn=Properties.Settings.Default.YourConnectionString;Thursday, October 9, 2008 7:35 AM