Saving Properties.Settings for a DLL project

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a DLL Winform project. I've double-clicked Settings.settings under
Properties, and create the following application setting:

Name: MySetting1, Type: string, Scope: Application, Value: c:\TestDocs

When I need the MySetting1 value, just use the following in my C# code:

string sVal = "WordDocGenDefaultDirectory";
string str = Properties.Settings.Default[sVal].ToString();

This gives me the value c:\TestDocs, which is exactly what I want. Great
stuff!

The user can specify a value other than c:\TestDocs, which needs to be
available the next time the program runs. I tried the following, which does
*not* save the new value.

Properties.Settings.Default[sVal] = newPath;
Properties.Settings.Save();

Any suggestions on how to save the new value so it's available the next time
the program runs?

Thanks,
 
Hi Randy,

You cannot save the application setting because the scope of this setting
is Application.

The crucial distinction between application-scope and user-scope settings
is that user-scope settings are read/write at run time, and their values
can be changed and saved in code. Application-scope settings are read only
at run time. While they can be read, they cannot be written to. Settings
with application scope can only be changed at design time, or by altering
the settings file manually.

The user-scope settings are put in user profile folder and can be written.
You can change the scope to User and your code works fine on my machine.

For more information, please check the following link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html
/SettingsCS_RL.asp

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top