473,385 Members | 1,373 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,385 software developers and data experts.

Can you write to the .config file?

..Net's .config file is supposed to replace the .ini files.
That's all fine if all I need is to read from it. But what
if I need both read and write? With .ini file, I can do
that very easily with standard API. But is there API for
writing the .config files? I know we can treat .config
file as a regular XML file and using XML API to write to
it, but is there API for writing to .config file just like
we read from it?

Thanks.

feng
Nov 20 '05 #1
4 1654
No. The app settings in the config file are meant to be read-only. As you
mentioned you can edit the config file using XML classes but if you want
read/write settings you should do it outside of the config file.

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"feng" <an*******@discussions.microsoft.com> wrote in message
news:df****************************@phx.gbl...
.Net's .config file is supposed to replace the .ini files.
That's all fine if all I need is to read from it. But what
if I need both read and write? With .ini file, I can do
that very easily with standard API. But is there API for
writing the .config files? I know we can treat .config
file as a regular XML file and using XML API to write to
it, but is there API for writing to .config file just like
we read from it?

Thanks.

feng

Nov 20 '05 #2
Feng:

Like Rob mentions, you can't write to it explicitly, however, I think I
heard a rumor that that's going to change in Whidbey (but I'm not positive).

Anyway, it's very easy to dupblicate though(although if you roll your own
you won't have the inherent designer support for dynamic properties). A
coworker of mine wrote this example
http://www.knowdotnet.com/articles/csettings.html that you may find helpful

HTH,

Bill
"feng" <an*******@discussions.microsoft.com> wrote in message
news:df****************************@phx.gbl...
.Net's .config file is supposed to replace the .ini files.
That's all fine if all I need is to read from it. But what
if I need both read and write? With .ini file, I can do
that very easily with standard API. But is there API for
writing the .config files? I know we can treat .config
file as a regular XML file and using XML API to write to
it, but is there API for writing to .config file just like
we read from it?

Thanks.

feng

Nov 20 '05 #3
* "feng" <an*******@discussions.microsoft.com> scripsit:
.Net's .config file is supposed to replace the .ini files.
That's all fine if all I need is to read from it. But what
if I need both read and write? With .ini file, I can do
that very easily with standard API. But is there API for
writing the .config files? I know we can treat .config
file as a regular XML file and using XML API to write to
it, but is there API for writing to .config file just like
we read from it?


Config files are not the right place to store "user preferences", so you
cannot write them.

Configuration Management Application Block
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/cmab.asp>

<http://www.palmbytes.de/content/dotnetlibs/optionslib.htm>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4

"feng" <an*******@discussions.microsoft.com> wrote in message
news:df****************************@phx.gbl...
.Net's .config file is supposed to replace the .ini files.
That's all fine if all I need is to read from it. But what
if I need both read and write? With .ini file, I can do
that very easily with standard API. But is there API for
writing the .config files? I know we can treat .config
file as a regular XML file and using XML API to write to
it, but is there API for writing to .config file just like
we read from it?

Thanks.

feng


It isn't the best recommended practice to write to the App.config file, but,
check tomorrow morning on my website http://www.tiberiansun.us/projects and
I will post my DLL up there that does exactly that. My suggestion, write
code to make your own XML file that replaces the traditional INI file. I
have attempted to start one, but just haven't had the time to finish it.
Some say "Use the registry", but I don't like that, I like using the XCopy
Install feature of .NET, just copy the files and run. Anyhew, check about
10am EST for the DLL there.

Sueffel
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.580 / Virus Database: 367 - Release Date: 2/6/2004
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
33
by: Nick Evans | last post by:
Hello there, I have been on and off learning to code (with python being the second language I have worked on after a bit of BASIC). What I really want to know is, if you are going to actually...
0
by: Joan Bos | last post by:
Hi, Is there somewhere on the Internet a description of what a .NET application config file should contain? For our application, I have to write passwords encrypted in a config file. The...
2
by: Shaun Ram | last post by:
Hi I have this constraint. A help would be greatly apprecitated. I have this Config file. <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <sectionGroup name="ITASCA">...
9
by: ALI-R | last post by:
Hi,, I have two questions : 1) Is it mandatory that config file of a desktop application must be App.config 2) Is it possible to update config file in your code?? thanks for your help. ALI
3
by: Agnes | last post by:
Can I write a file like config.ini which store the server-name, userid & password, So, my application can read the config.ini file and get the server - name, Does my concept is correct ? If...
4
by: Jeff smith | last post by:
I am reading the value from config file using the below statement. System.Configuration.ConfigurationSettings.AppSettings("MY_DATA") How to write data back to the same location? I am using...
1
by: Lialie | last post by:
Hello,all I found it easy to read configures from a config file. But how can I set a special value to an item or write it into the original file? I have tried this: import ConfigParser config...
4
by: apriebe47 | last post by:
Alright, I realize this is probably very basic to be posted on this newsgroup but I cannot figure out what is causing my problem. Here is the code I am using below: from getpass import getpass ...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.