473,587 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

writing into config file

13 New Member
how to write values into app config files using c# code in windows forms applications
Apr 19 '10 #1
14 2902
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. config.AppSettings.Settings["newVal"].Value = "100";    
  2.  
Regards
Dheeraj Joshi
Apr 19 '10 #2
E481610
13 New Member
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?
Apr 19 '10 #3
MrMancunian
569 Recognized Expert Contributor
"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 Recognized Expert Top Contributor
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 New Member
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?
Apr 19 '10 #6
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
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 New Member
@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.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
Apr 19 '10 #8
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
@E481610
What is the error?

Regards
Dheeraj Joshi
Apr 19 '10 #9
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
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

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

Similar topics

6
577
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 System.Configuration) like the ConfigurationSettings.AppSettings property, but I was not able to find anything to write app settings in these files. Isn't this kind...
4
1562
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 would also like to be able to write to it. TIA - Jeff.
2
12690
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
2521
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 settings? What is the standard method of saving user settings for VB.Net apps?
1
2301
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 password txtServername = Sql Server name I want to be able to write the input supplied by users to the App.config file..
9
3780
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 a windows program to get the string and I don't know if I can use the WebConfigurationManager API to read and write my web config from a windows...
0
1079
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 file and then overwrite it. Values in new config file then restored from old file: setNew.Value.ValueXml.InnerXml = setOld.Value.ValueXml.InnerXml; ...
6
2897
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 bellow, and its almost idenictal to every web example i have found. They all suggest the values and file can be read from and updated. The code...
0
1151
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 between these application was xml datasource tag in web.config such as: Application 1 <appSettings> <add key="DataFileName" value="Abc.XML" /> ...
3
1746
by: John | last post by:
Hi Is there any easy way to write strings into a file for debugging purposes? Thanks Regards
0
7918
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.