create app.config during runtime from within code

C

Christian Muggli

can someone explain me how to create a app.config file during runtime? i see
two ways:

- add a skeleton of an app.config file to the exe/dll and extract it during
runtime as a resource and extract
OR
- create a app.config file using xml

is there another way?

thanks

christian
 
N

Nicholas Paldino [.NET/C# MVP]

Christian,

Well, if you really want to get rudimentary, you could create a
FileStream instance and write it byte by byte.

But I doubt you want to do that.

Usually, the configuration sections have object models that you can
access through the classes in the System.Configuration namespace. You could
try working with these models in code and then persist them to another file
(although because config files are not written to, except for user setting
sections, it might be the case that there is not much support for going from
the config object to XML, only vice versa).
 
P

Peter Bromberg [C# MVP]

You could certainly keep a bare-bones config file as an embedded resource and
extract and save it next to the executable. You could also use the classes in
System.Configuration to work with, edit and resave your modified config file.
But that's with the proviso that the app only loads an existing config file
one time - when it's first run. So you'd need some mechanism to force it to
be reloaded once modified, unless you plan on only having it take effect when
the application is restarted.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
 

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