Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save user.config to AppData\Roaming folder instead of AppData\Local?

Tags:

Introductory Example

This code

Properties.Settings.Default.MyUserSettingBlah = "some new value";
Properties.Settings.Default.Save();

saves the user.config file to

C:\Users\MyUserName\AppData\Local\My_Company_Name\MyApp_Url_vb2s5kwidefdmxstmabckatcyl5t0lxd\1.0.0.0\user.config

Question

How can I save user.config to

  • C:\Users\MyUserName\AppData\ Roaming \...

instead of

  • C:\Users\MyUserName\AppData\ Local \... ?
like image 362
Lernkurve Avatar asked Jul 22 '10 10:07

Lernkurve


People also ask

What is the difference between AppData local and AppData Roaming?

AppData folder contains user-specific preferences and profile configurations and is further divided into three subfolders: Roaming folder contains data that can move with the user profile from a computer to a computer. Local folder contains data that cannot move with your user profile.

What is AppData Roaming folder?

AppData\Roaming is where programs on your machine store data that is specific to your user account. The folder is normally hidden, and lives within your user account home folder.

Why does Windows have an AppData folder?

The AppData folder contains all the data specific to your Windows user profile. This means that your data can be transferred from one device to another as long as you sign in with the same profile. Several apps use the AppData folder so it's easy to keep data synced between devices.

How do you locate the application data folder and how is it different from the program files folder?

You can either access it manually or by using the "AppData" variable name. You can view the AppData folder manually by going into your Users folder, which is there in the C drive. In my case, the path is C:\Users\ADMIN . Now you should be able to see the AppData folder in your User folder.


2 Answers

I stumbled on this now...

As far as I know, it should be that you should put:

[global::System.Configuration.SettingsManageability(System.Configuration.SettingsManageability.Roaming)]        

in Settings.Designer.cs for each settng that should go to roaming profile.

Alternatively you can change this on the Settings screen in Visual Studio 2010 by selecting the setting(s) and displaying it's properties (F4). There you can set the Roaming property to True.

like image 185
Ivan Ičin Avatar answered Sep 19 '22 09:09

Ivan Ičin


I don't know if it's a new feature or not, but in VS2010 every setting has a property called Roaming that can be set to true or false.
It's not visible in the Settings designer though, you have to set it in the properties window for the setting you'd like to use it on.

Setting that property to true on a setting adds

[global::System.Configuration.SettingsManageabilityAttribute(global::System.Configuration.SettingsManageability.Roaming)]

to Settings.Designer.cs for that particular setting, which is almost identical to what Ivan suggested.

like image 39
takrl Avatar answered Sep 21 '22 09:09

takrl