Home All Groups Group Topic Archive Search About
Author
8 Aug 2006 2:00 PM
Nicolas Zenou
Hello everyone,

I m trying to use the ConfigurationManager class to store and retrieve
configuration data for my application.

My piece of code can create, write and read data from the file but when my
application close, the configuration file disappear.
In fact, when I use the "debug" to launch and test my application the
app.exe.config is created and when the application finish, the file is
deleted.
When I try to generate the application, the app.exe.config isn't created too.

How can I do to create this file and to keep it not deleted?

Here what I m using:

Public Shared Sub Write(ByVal entry As String, ByVal value As String)
Try

Dim Config As Configuration =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

Config.AppSettings.Settings.Add(entry, value)
Config.AppSettings.Settings.Item(entry).Value = value
Config.Save(ConfigurationSaveMode.Modified)
ConfigurationManager.RefreshSection("appSettings")

Catch ex As Exception
MsgBox(ex.ToString())
End Try

End Sub

Thanks a lot or your answers.

Author
8 Aug 2006 3:06 PM
Leon Mayne
> I m trying to use the ConfigurationManager class to store and retrieve
> configuration data for my application.
>
> My piece of code can create, write and read data from the file but when my
> application close, the configuration file disappear.
> In fact, when I use the "debug" to launch and test my application the
> app.exe.config is created and when the application finish, the file is
> deleted.
> When I try to generate the application, the app.exe.config isn't created too.
>
> How can I do to create this file and to keep it not deleted?

Do you have an App.Config file added to your project? If you are creating it
on the fly when the app runs then perhaps it is automatically deleted. Add an
application configuration file to your project at design time and see if that
works.
Author
9 Aug 2006 3:42 PM
Nicolas Zenou
Thanks for answering.

I don't see any application configuration file I can add to my project at
design. Are ou sure we can add a configuration file at design? Is it a
compenent that I have to add to the list of design compenent?


Show quoteHide quote
> works.

"Leon Mayne" wrote:

> > I m trying to use the ConfigurationManager class to store and retrieve
> > configuration data for my application.
> >
> > My piece of code can create, write and read data from the file but when my
> > application close, the configuration file disappear.
> > In fact, when I use the "debug" to launch and test my application the
> > app.exe.config is created and when the application finish, the file is
> > deleted.
> > When I try to generate the application, the app.exe.config isn't created too.
> >
> > How can I do to create this file and to keep it not deleted?
>
> Do you have an App.Config file added to your project? If you are creating it
> on the fly when the app runs then perhaps it is automatically deleted. Add an
> application configuration file to your project at design time and see if that
> works.
Author
9 Aug 2006 3:55 PM
Leon Mayne
> I don't see any application configuration file I can add to my project at
> design. Are ou sure we can add a configuration file at design? Is it a
> compenent that I have to add to the list of design compenent?

Right-click your project in solution explorer, select Add / Add new item,
and select Application Configuration File