Connecting Tech Pros Worldwide Help | Site Map

Accessing config files programatically

Simon Harvey
Guest
 
Posts: n/a
#1: Nov 15 '05
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


Bruno Jouhier [MVP]
Guest
 
Posts: n/a
#2: Nov 15 '05

re: Accessing config files programatically


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.

"Simon Harvey" <sh856531@microsofts_free_email_service.com> a écrit dans le
message de news:uaUhb0$5DHA.4060@tk2msftngp13.phx.gbl...[color=blue]
> 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[/color]
file[color=blue]
> easily as well.
>
> Also, my application doesnt actually have a config file created by[/color]
default.[color=blue]
> 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
>
>[/color]


Bruno Jouhier [MVP]
Guest
 
Posts: n/a
#3: Nov 15 '05

re: Accessing config files programatically


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

Bruno


Stu Smith
Guest
 
Posts: n/a
#4: Nov 15 '05

re: Accessing config files programatically


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.


"Bruno Jouhier [MVP]" <bjouhier@club-internet.fr> wrote in message
news:%23B31ylA6DHA.3304@tk2msftngp13.phx.gbl...[color=blue]
> 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[/color]
MyApp.exe.config.[color=blue]
>
> Also, don't try to create MyApp.exe.config directly into bin\Debug, it[/color]
will[color=blue]
> get overwritten every time you compile.
>
> Bruno.
>
> "Simon Harvey" <sh856531@microsofts_free_email_service.com> a écrit dans[/color]
le[color=blue]
> message de news:uaUhb0$5DHA.4060@tk2msftngp13.phx.gbl...[color=green]
> > 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[/color]
> file[color=green]
> > easily as well.
> >
> > Also, my application doesnt actually have a config file created by[/color]
> default.[color=green]
> > I thought the VS template would create one automatically but it doesnt.[/color][/color]
Is[color=blue][color=green]
> > it ok just to make one in the form:
> >
> > MyApp.exe.config
> >
> > Will that work?
> >
> > Thanbks everyone
> >
> > Simon
> >
> >[/color]
>
>[/color]


Closed Thread