how to write values into app config files using c# code in windows forms applications
writing into config file
Collapse
X
-
-
about error in writing into the app.config file
hi
just now i have the the code
config.AppSetti ngs.Settings["newVal"].Value = "100";
for writing into app.config file
but the error it is showing is
"Object reference not set to an instance of an object."
can u please clarify my doubt?Comment
-
"Object reference not set to an instance of an object." means that you are referring to an object without a value. It can be solved by declaring the object as New. Can you post the code that gives you the error?
StevenComment
-
Does "newVal" exists in app.config?
Regards
Dheeraj Joshi
To OP: Please do not start new thread when you have problem with same isuue. Continue posting in same thread. In this thread you asked how to write into app.config. Now you have problem in writing to it, so according to rules you need to post in same thread not to start new one.Comment
-
how to retrieve the written key and its value at once?
hi i have written into the app config file by using the code
config.AppSetti ngs.Settings.Ad d("srinu","100" );
where "srinu" is the key , and "100" is its value
now what i want to do is........ i have to display those key and its value in two different text fields by the click of the button
can u please reply me fast?Comment
-
Get the value of the key from the app.config and display it.
Something like this
Code:String myVal = System.Configuration.ConfigurationSettings.AppSettings["newVal"].toString();
Dheeraj JoshiComment
-
the code u sent is for the key and value that were in app.config file
but what i want to retrieve is....to retrieve key and value that are externally written using some writing into app.config file codes
just check the code below
System.Configur ation.Configura tion config = ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None);
/* XmlDocument doc =
XmlNode node = doc.SelectSingl eNode("//appSettings");*/
string c = config.AppSetti ngs.Settings["secondname "].Value = "100";
//string k =Keys(config.Ap pSettings.Setti ngs["govinda"].Value) = "modifiedvalue" ;
//config.AppSetti ngs.Settings.Ad d("Modification Date", DateTime.Now.To LongTimeString( ) + " ");
//textBox2.Text = c;
string[] keys = appSettings.All Keys;
config.AppSetti ngs.Settings.Ad d("srinu","100" );
config.Save(Con figurationSaveM ode.Modified);
String myVal = System.Configur ation.Configura tionSettings.Ap pSettings["100"].ToString();
textBox1.Text = keys[1];
textBox2.Text = myVal;
here "keys" is an array having only 2 values means upto keys[1] it exists
but when i give textBox1.Text = keys[2];
it is showing error eventhough i have written another "srinu" key into config fileComment
-
hi
the code u sent is for the key and value that were in app.config file
but what i want to retrieve is....to retrieve key and value that are externally written using some writing into app.config file codes
just check the code below
System.Configur ation.Configura tion config = ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None);
/* XmlDocument doc =
XmlNode node = doc.SelectSingl eNode("//appSettings");*/
string c = config.AppSetti ngs.Settings["secondname "].Value = "100";
//string k =Keys(config.Ap pSettings.Setti ngs["govinda"].Value) = "modifiedvalue" ;
//config.AppSetti ngs.Settings.Ad d("Modification Date", DateTime.Now.To LongTimeString( ) + " ");
//textBox2.Text = c;
string[] keys = appSettings.All Keys;
config.AppSetti ngs.Settings.Ad d("srinu","100" );
config.Save(Con figurationSaveM ode.Modified);
String myVal = System.Configur ation.Configura tionSettings.Ap pSettings["100"].ToString();
textBox1.Text = keys[1];
textBox2.Text = myVal;
here "keys" is an array having only 2 values means upto keys[1] it exists
but when i give textBox1.Text = keys[2];
it is showing error eventhough i have written another "srinu" key into config file
Regards
Dheeraj JoshiComment
-
Code:String myVal = System.Configuration.ConfigurationSettings.AppSett ings["100"].ToString();
Code:String myVal=System.Configuration.ConfigurationSettings.AppSettings["secondname"].ToString();
Dheeraj JoshiComment
-
Comment
-
hi i have written into the app config file by using the code
config.AppSetti ngs.Settings.Ad d("srinu","100" );
where "srinu" is the key , and "100" is its value
now what i want to do is........ i have to display those key and its value in two different text fields by the click of the button
can u please reply me fast?
can i get ur reply soon please?Comment
-
Comment
Comment