473,325 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

writing into config file

13
how to write values into app config files using c# code in windows forms applications
Apr 19 '10 #1
14 2882
Dheeraj Joshi
1,123 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. config.AppSettings.Settings["newVal"].Value = "100";    
  2.  
Regards
Dheeraj Joshi
Apr 19 '10 #2
E481610
13
hi
just now i have the the code
config.AppSettings.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?
Apr 19 '10 #3
MrMancunian
569 Expert 512MB
"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?

Steven
Apr 19 '10 #4
Dheeraj Joshi
1,123 Expert 1GB
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.
Apr 19 '10 #5
E481610
13
hi i have written into the app config file by using the code
config.AppSettings.Settings.Add("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?
Apr 19 '10 #6
Dheeraj Joshi
1,123 Expert 1GB
Get the value of the key from the app.config and display it.

Something like this
Expand|Select|Wrap|Line Numbers
  1. String myVal = System.Configuration.ConfigurationSettings.AppSettings["newVal"].toString();
  2.  
Regards
Dheeraj Joshi
Apr 19 '10 #7
E481610
13
@dheerajjoshim
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.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(Configur ationUserLevel.None);
/* XmlDocument doc =
XmlNode node = doc.SelectSingleNode("//appSettings");*/
string c = config.AppSettings.Settings["secondname"].Value = "100";
//string k =Keys(config.AppSettings.Settings["govinda"].Value) = "modifiedvalue";
//config.AppSettings.Settings.Add("ModificationDate" , DateTime.Now.ToLongTimeString() + " ");
//textBox2.Text = c;
string[] keys = appSettings.AllKeys;
config.AppSettings.Settings.Add("srinu","100");
config.Save(ConfigurationSaveMode.Modified);

String myVal = System.Configuration.ConfigurationSettings.AppSett ings["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
Apr 19 '10 #8
Dheeraj Joshi
1,123 Expert 1GB
@E481610
What is the error?

Regards
Dheeraj Joshi
Apr 19 '10 #9
Dheeraj Joshi
1,123 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. String myVal = System.Configuration.ConfigurationSettings.AppSett ings["100"].ToString();
  2.  
This is wrong it must be

Expand|Select|Wrap|Line Numbers
  1. String myVal=System.Configuration.ConfigurationSettings.AppSettings["secondname"].ToString();
  2.  
Regards
Dheeraj Joshi
Apr 19 '10 #10
E481610
13
@dheerajjoshim
"object reference not set to an instance of an object"
this is the error
Apr 19 '10 #11
MrMancunian
569 Expert 512MB
@E481610: Stop creating new topics for this problem. Just post it all in the same topic.
Apr 19 '10 #12
E481610
13
@E481610
hi dheeraj
can i get ur reply soon please?
Apr 19 '10 #13
Dheeraj Joshi
1,123 Expert 1GB
Keys is an array and array index starts from 0

Try keys[0] and keys[1]

Regards
Dheeraj Joshi
Apr 19 '10 #14
tlhintoq
3,525 Expert 2GB
Since all of your threads are on the same subject of App.config they have all been merged.

In the future please keep one thread for one subject.
Apr 19 '10 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: msnews.microsoft.com | last post by:
Hi all, I was trying to find an easy way to write in the standard configuration (like app.config) xml-based files. I found classes that can be used to read this information (in...
4
by: UJ | last post by:
Is there a way to write into the .config file? In other words treat it like a .ini file. (I may be confused on what the exact nature of the .config file may be.) I can read from it fine but...
2
by: MK | last post by:
Is there any way to write into the app config at runtime? I want to store position, height and width of my forms.
19
by: Noozer | last post by:
I need to keep my application settings in a file that users can copy/backup/etc. Before I start using the old INI file standard, is there any easy way to use XML files to hold application...
1
by: ROO | last post by:
Hi Everyone, I need some help Creating Database Connection at runtime and writing Connection String to App.Config, I have 3mxtboxes on a form txtUsername = SQL admin User txtPassword = Sql admin...
9
by: WT | last post by:
Hello, I am writing a Web install project and I want to get the connection string from user and write it in the web.config of the installed web site. As the Websetup is a windows program, I use...
0
by: Rum | last post by:
Hi, I`m writing an application that can be updated from remote server. Application config file is updating too (adding new sections etc...) When application is updating i make a copy of old config...
6
by: Peted | last post by:
Hi, im wanting to store some custom text strings in the app.config file of a c# app, to be retreived and updated when the app runs. using c# 2005 express in my testing i am using the code...
0
parshupooja
by: parshupooja | last post by:
Hey All, I have old vb.net application and I have various users for that.where I have XML file as datasource. Till now for each user application was installed seperately. only difference...
3
by: John | last post by:
Hi Is there any easy way to write strings into a file for debugging purposes? Thanks Regards
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.