Accessing config files programatically

S

Simon Harvey

Hi chaps,

Can someone direct me to the necessary class that will allow me to write
information into my applications .config file? I know how to read
information but I'm sure there must be a way to write out to the config file
easily as well.

Also, my application doesnt actually have a config file created by default.
I thought the VS template would create one automatically but it doesnt. Is
it ok just to make one in the form:

MyApp.exe.config

Will that work?

Thanbks everyone

Simon
 
B

Bruno Jouhier [MVP]

The API only allows you to write from it.

In VStudio, you have to create a file called app.config (not
myapp.exe.config) in your project's base directory and you have to include
it into your projet (it will be included by default if you create it with
VStudio but not if you create it outside of Studio).
Then, when you compile your project, Studio will copy it to bin/Debug or
bin/Release depending on the config, and it will rename it MyApp.exe.config.

Also, don't try to create MyApp.exe.config directly into bin\Debug, it will
get overwritten every time you compile.

Bruno.
 
B

Bruno Jouhier [MVP]

The API only allows you to write from it.
Of course, I meant READ from it. I must be tired.

Bruno
 
S

Stu Smith

The reason there's no API to write to it of course is that your app could be
running under lock-down mode -- no write access to Program Files etc. The
standard pattern is to look for a user-specific file (under Documents and
Settings ... Application Data), and if that can't be found, read the
application one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top