Where are My.Settings saved in VB 2010 .NET?
Asked Answered
M

4

19

Are My.Settings values saved in the program itself or do they get stored in the registry? So, for example, if I set a My.Settings value with a program, then I copy the program itself to another PC - is the My.Settings value still set?

Marks answered 1/1, 2012 at 4:35 Comment(1)
no, if it is User settings. Only Application Settings would come to your application.Enrollment
S
36

It depends upon the scope you have selected. There are two scope settings - Application and User scope.

From MSDN article:

Application-scoped settings are read-only and are shared between all users of that application. These settings are stored in the app.config file in the section. At run time, the app.config file will be in your bin folder and will be named with your application's name (MySettingsDemo.exe.config).

User-scope settings are specific for each user. They can be read and set safely by the application code at run time. These settings are stored in a user.config file. To be technically accurate, there are two user.configs per user per application—one for non-roaming and one for roaming. Although the Visual Basic 2005 documentation states that the user.config file will be named according to the user's name (joe.config), this is not the case. The user.config file is created in the:

<c:\Documents and Settings>\<username>\[LocalSettings\]ApplicationData\<companyname>\<appdomainname>_<eid>_<hash>\<verison>.
Schaeffer answered 1/1, 2012 at 4:43 Comment(0)
M
16
Dim config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal)
MessageBox.Show(config.FilePath)
Mahalia answered 2/12, 2015 at 6:17 Comment(1)
This is the only correct answer, that is independent of VS version. For per-user installs they are stored in something meaningless like C:\Users\[YOURNAME]\AppData\Local\Microsoft_Corporation\DefaultDomain_Path_jojpsvsna1vaszvd35jsryd0vnvv001i\16.0.11601.20144\user.configLaure
M
4

If you have installed your application using clickonce then your MySettings will be stored in a config file which is stored at `C:\Users\\AppData\Local\Apps\2.0\Data........

search in these path with a file named as yourapp.exe.config

The thing is MySettings will be stored in app.config file of that application and after publishing the app.config file is saved as applicationname.exe.config file

Mudd answered 1/1, 2012 at 5:26 Comment(0)
M
3

They're definitely not stored within the program if they're User settings - that's not very easy to implement, and rather pointless. Rather, they're stored in a configuration file in the %AppData% folder. So no, if you copied the program, the User settings wouldn't come with it, just the Application settings.

Manganate answered 1/1, 2012 at 4:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.