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

2

22

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 \... ?
Salim answered 22/7, 2010 at 10:6 Comment(0)
I
31

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.

Immediate answered 28/11, 2010 at 18:17 Comment(2)
@christian studer: Nice. Thanks!Salim
Do you know how to determine the roaming property of a setting using C#?Cylinder
R
11

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.

Roomer answered 6/4, 2011 at 14:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.