My.settings are lost if location is changed

K

kimiraikkonen

Hi,
I used My.Settings namespace to store application settings well. If i
don't change its location, i can call saved settings OK. But maybe
it's a bug or not, if i change my application location to another
folder or drive partition, it gets lost!

How can avoid this?

Thanks.
 
W

Wolf Saenger

Hello kimiraikkonen,

use -> system.Cnfiguration

somevalue = System.Configuration.ConfigurationManager.ApplicationSettings("SOMEVALUE")
 
M

Michel Posseth [MCP]

no it is not a bug it is obvious behavior ( imho it is by design )

user's application settings in a user.config file are saved in the user's
desktop profile

non-roaming settings, user.config file is located at %USERPROFILE%\Local
Settings\Application Data\<Company
Name>\<appdomainname>_<eid>_<hash>\<verison>\user.config.


roaming user settings, user.config file is located at
%USERPROFILE%\Application Data\<Company
Name>\<appdomainname>_<eid>_<hash>\<verison>\user.config.


values are stored to the file after calling My.Settings.Save or on shutdown
of the app if save my settings on exit box is checked in the properties
window of the application


Look for the above locations and you will see that for every version of your
program ( new compile or alternate location ) a different hash is generated
thus different settings file .

HTH



Michel
 
K

kimiraikkonen

no it is not a bug it is obvious behavior ( imho it is by design )

user's application settings in a user.config file are saved in the user's
desktop profile

non-roaming settings, user.config file is located at %USERPROFILE%\Local
Settings\Application Data\<Company
Name>\<appdomainname>_<eid>_<hash>\<verison>\user.config.

roaming user settings, user.config file is located at
%USERPROFILE%\Application Data\<Company
Name>\<appdomainname>_<eid>_<hash>\<verison>\user.config.

There's no entry related to my application there, only a .config file
under debug folder in VS 2005 projects, but when i took a look at via
notepad to it, there are only default values stored, but
interestingly, i can call the saved settings with no problem if i
DON'T change the location.

Where are exactly the settings stored?
values are stored to the file after calling My.Settings.Save or on shutdown
of the app if save my settings on exit box is checked in the properties
window of the application

Look for the above locations and you will see that for every version of your
program ( new compile or alternate location ) a different hash is generated
thus different settings file .

HTH

Michel

Thanks
 
T

Teemu

Where are exactly the settings stored?

As Michel said they should be found in following location:

%USERPROFILE%\Application Data\Local\<app name>

If your are using XP, the path could be for example:

C:\Documents and Settings\<Your name>\Application Data\<program
name/company>

It is possible that Explorer won't show these folders if you haven't change
the default settings but this is the right location. The file where settings
are saved is user.config.

-Teemu
 
K

kimiraikkonen

As Michel said they should be found in following location:

%USERPROFILE%\Application Data\Local\<app name>

If your are using XP, the path could be for example:

C:\Documents and Settings\<Your name>\Application Data\<program
name/company>

It is possible that Explorer won't show these folders if you haven't change
the default settings but this is the right location. The file where settings
are saved is user.config.

-Teemu

Hi Teemu,
Yes there are some programs with their settings, but there's
no .config file of my project. I didn't used any installer or publish.
I only execute through My Documents\Visual Studio 2005\projects\<myapp>
\<myapp>\bin\debug\myapp.exe

Could it be the reason?
 
T

Teemu

Hi Teemu,
Yes there are some programs with their settings, but there's
no .config file of my project. I didn't used any installer or publish.
I only execute through My Documents\Visual Studio 2005\projects\<myapp>
\<myapp>\bin\debug\myapp.exe

Could it be the reason?

No. Try also Documents and Settings\All Users folder. File might be there if
the scope of your settings is Application not User.

-Teemu
 
K

kimiraikkonen

No. Try also Documents and Settings\All Users folder. File might be there if
the scope of your settings is Application not User.

-Teemu

Forget all. I searched the file named "myapp.config" with no result
(Windows search function). Then i searched "myapp.exe.config" file
with results but none of them seems to store my previously saved
settings and no setting file related to myapp which is located in
Application / User / Local Settings. So what could it be?

(Meanwhile, I can still call settings fine if no location change.)
 
T

Teemu

Forget all. I searched the file named "myapp.config" with no result
(Windows search function). Then i searched "myapp.exe.config" file
with results but none of them seems to store my previously saved
settings and no setting file related to myapp which is located in
Application / User / Local Settings. So what could it be?

As I mentioned earlier the filename is user.config

-Teemu
 
K

kimiraikkonen

As I mentioned earlier the filename is user.config

-Teemu

Hi Teemu,
At last i've found the user.config of my file by searching "hidden
files/folder" in Windows search function by enabling hidden file
search checkbox.

But the user.config's location is weird:
C:\Documents and Settings\Kimi\Local Settings\Application Data\Home
\myapp.exe_Url_xspaixx0xb5icu2kjk50ulbjcz1bp34y\1.0.0.0

Thanks.
 
T

Teemu

Hi Teemu,
At last i've found the user.config of my file by searching "hidden
files/folder" in Windows search function by enabling hidden file
search checkbox.

But the user.config's location is weird:
C:\Documents and Settings\Kimi\Local Settings\Application Data\Home
\myapp.exe_Url_xspaixx0xb5icu2kjk50ulbjcz1bp34y\1.0.0.0

Thanks.

Finally. :)

That strange part is a hash for your program. It changes when you modify
your code or when you move your program. This is why your settings
disappear.

I'm not sure if My.Settings.Upgrade() works for this but you could try it.

-Teemu
 
S

ShaneO

kimiraikkonen said:
Hi,
I used My.Settings namespace to store application settings well. If i
don't change its location, i can call saved settings OK. But maybe
it's a bug or not, if i change my application location to another
folder or drive partition, it gets lost!

How can avoid this?

Thanks.

Here's what I do to overcome this problem -

1. In the applications Properties section, create a setting such as
"SettingsValid" and set its Type as Boolean.
2. Make sure you set its Default Value to "False".
3. In the Form_Load Event I add -

If Not My.Settings.SettingsValid Then
My.Settings.Upgrade()
My.Settings.SettingsValid = True
My.Settings.Save()
End If

This should fix your problem.

Works for me!

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
K

kimiraikkonen

no it is not a bug it is obvious behavior ( imho it is by design )

user's application settings in a user.config file are saved in the user's
desktop profile

non-roaming settings, user.config file is located at %USERPROFILE%\Local
Settings\Application Data\<Company
Name>\<appdomainname>_<eid>_<hash>\<verison>\user.config.

roaming user settings, user.config file is located at
%USERPROFILE%\Application Data\<Company
Name>\<appdomainname>_<eid>_<hash>\<verison>\user.config.

values are stored to the file after calling My.Settings.Save or on shutdown
of the app if save my settings on exit box is checked in the properties
window of the application

Look for the above locations and you will see that for every version of your
program ( new compile or alternate location ) a different hash is generated
thus different settings file .

HTH

Michel

But isn't it a mistake? I Because the settings must be stored in root
folder as a single file(whatever its extension is not matter, ini or
XML) and whereever aplication is moved to another location, then the
settings file is moved to new location together, too.

Think about .ini files (i don't know how they're used in VB.NET) but
since their existence, usually they are used to store application
settings placed in root folder of application. So, whereever
application is moved to, the settings file will be called even in new
location well although location change unline vb.net's my.settings
feature.

That was all i wanted to point out.

Thanks.
 
K

kimiraikkonen

But isn't it a mistake? I Because the settings must be stored in root
folder as a single file(whatever its extension is not matter, ini or
XML) and whereever aplication is moved to another location, then the
settings file is moved to new location together, too.

Think about .ini files (i don't know how they're used in VB.NET) but
since their existence, usually they are used to store application
settings placed in root folder of application. So, whereever
application is moved to, the settings file will be called even in new
location well although location change unline vb.net's my.settings
feature.

That was all i wanted to point out.

Thanks.

For this problem (setting loss due to application location change),
should i go with storing application settings with INI files instead
of XML files? I remember "ini" files can be stored on app's root
folder generally and is moved anywere with the application if a
location change occurs with no data loss.

By default .NET's "my.settings" feature saves .config (XML coded) file
to C:\Documents and Settings\<name>\Local Settings\Application Data
\<company> or similiar like that as user.config file and if i move my
app(not user.config) another location settings are lost.

So, should i change setting storage to ".ini" files which is very
classic?

How can i read / write to "ini" files? I read some resources claim
that an API call maybe needed, however some non-API methods were
succeced in some cases.

I hope to know more about ".ini" files for settings storage.

Thanks.
 

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