efriese

I'm writing an app where I need to save some inputs from the user. I cannot use the app.config method because the users will not have admin access on their machines.

I've tried doing this through the Visual Studio IDE, but its still outputting the settings to app.config (I cannot even get it to read the settings back in). Does anyone know if there is a way in .NET to do this. My alternative is to write the code to do it and I was trying to avoid that. Thanks for your help!



Re: Visual C# General Saving User Settings

Mark Benningfield

Hello All.

efriese:

If you use user-scoped settings, your app will save them on a per-user basis in that user's isolated storage, in yourappname\user.config. Then all your users need to have is isolated storage access privelege, which even restricted user's have.

HTH.






Re: Visual C# General Saving User Settings

efriese

That's exactly what I'm trying to do, but it's outputting them to the app.config file in the same directory as the executable. Is there a setting somewhere that I need to set





Re: Visual C# General Saving User Settings

Mark Benningfield

Hello All.

efriese:

Okay, I've noticed that the docs are a bit at odds with themselves over application settings, so sometimes it gets more complicated than it has to be.

You didn't specify, so I'm going to assume we're talking about a Windows Forms app; if this is a web app, you need to be in the ASP.NET forums, 'cause web.config has its own idiosyncracies.

In the Solution Explorer, expand the Properties heading for the project, and you will see Settings.settings. Double-click on that, and the Settings Editor will open, showing 4 columns: Name, Type, Scope, and Value. In the Scope column, make sure that the scope is User, not Application. Edit the other parameters to suit your needs, and build your project.

Visual Studio will generate code for a strongly-typed settings class, which you can reference in your code, like so: YourAppName.Properties.Settings.SettingName, using the generated setters and getters. If you select View Code in the Settings Editor, you will see facilities for wiring up the generated events for those settings, which are fired before and after changes and saves.

The settings are loaded automatically when your app starts, either using the user.config file for the current user, if his or her settings have been saved before, or the default values you choose to provide at design time. To persist settings for the current user, either using the defaults or the choices that user made, call YourAppName.Properties.Settings.Save().

That's all there is to it.

HTH.






Re: Visual C# General Saving User Settings

efriese

Mark,

Thanks for your help so far. I did as you said, but it is still outputting the settings to app.config in the same directory that the executable is in. That's not going to work for my users because they won't have admin privileges plus this method only allows for one set of settings to be stored.

2 questions:
1.) Is there a way to make the settings file be saved to the Application Data in the user's Documents and Settings directory

2.) I have a text box on my form. In the Application Settings section of the properties, I've linked the Text to one of my application settings. Whenever the text in the textbox is entered, it is not firing the SettingChangingEventHandler. Do I need to grab the TextChanging event and manually set the application setting value

Thanks for your help!





Re: Visual C# General Saving User Settings

Mark Benningfield

Hello All.

efriese:

The appname.config file in the .exe directory is where the default setting values are stored. The persistent settings for each user are in that user's isolated storage, which changes depending on whether the user is a roaming user or not. Generally, it is in user\Documents and Settings\Local Settings\Application Data\appname.exe_Url_gobbledygook\version number\

You can add as many strongly-typed settings classes as you want, just go to Project -> Add New Item ... , select Settings File, and proceed from there.

Oh, I have one correction to make to my earlier post. I inadvertently left off the Default member, so the actual reference is Properties.Settings.Default.SettingName. Sorry about that. For any additional settings objects, the reference is SettingsFileName.Default.SettingName. And again, to save the settings, it is Properties.Settings.Default.Save() .

For the SettingsChanging event, did you select "View Code" in the Settings Editor and follow the steps to enable and handle the settings events If you do not un-comment the event subscriptions and add code in the event handlers, then nothing will happen when the event is fired. That particular event is fired when you assign a value to one of the settings, before the value is actually changed. The SettingsChanged event fires after the value of the setting has actually been changed.

HTH






Re: Visual C# General Saving User Settings

RizwanSharp

saving settings using client Setting features of .Net 2.0 doesnot require any Administrative Previllages, All you need to do it to add a new setting, set its type, put the value, save and that is read to be used by your application as simple as:

string someValueInSetting = global::YourNameSpace.Properties.Setting.Default.MyStringSetting;

You want to change it

global::YourNameSpace.Properties.Setting.Default.MyStringSetting = "RizwanSharp";

global::YourNameSpace.Properties.Setting.Default.Save(); // Save the Setting.

You can define each setting to be Application level or User Level which is managed by Scope of that setting.

You dont need to be worried where those settings are stored because all you need to do is to use Properties, methods and events to interact with Client Setting. But these settings are stored in Application Data folder under each user's account.

I hope this will help.

Best Regards,

Rizwan aka RizwanSharp