<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Cool Client Stuff : Configuration/Settings</title><link>http://blogs.msdn.com/rprabhu/archive/category/6591.aspx</link><description /><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Client Settings FAQ updated</title><link>http://blogs.msdn.com/rprabhu/archive/2005/12/10/502438.aspx</link><pubDate>Sun, 11 Dec 2005 01:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:502438</guid><dc:creator>rprabhu</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/rprabhu/comments/502438.aspx</comments><wfw:commentRss>http://blogs.msdn.com/rprabhu/commentrss.aspx?PostID=502438</wfw:commentRss><description>I finally got around to updating my &lt;a href="http://blogs.msdn.com/rprabhu/articles/433979.aspx"&gt;FAQ&lt;/A&gt; on the settings feature in .NET 2.0. Look for&amp;nbsp;'&lt;EM&gt;Update: 12/10/2005&lt;/EM&gt;' to identify the new content. The new stuff is mostly some questions frequently asked on forums and internal mailing lists in Microsoft around security, configuration and availability of the settings feature in non-Windows Forms applications.&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=502438" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/rprabhu/archive/tags/Configuration_2F00_Settings/default.aspx">Configuration/Settings</category></item><item><title>Saving out a Form's Size and Location using the Application Settings feature</title><link>http://blogs.msdn.com/rprabhu/archive/2005/11/28/497792.aspx</link><pubDate>Tue, 29 Nov 2005 10:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:497792</guid><dc:creator>rprabhu</dc:creator><slash:comments>10</slash:comments><comments>http://blogs.msdn.com/rprabhu/comments/497792.aspx</comments><wfw:commentRss>http://blogs.msdn.com/rprabhu/commentrss.aspx?PostID=497792</wfw:commentRss><description>&lt;P&gt;A very common requirement for Windows Forms applications is the ability to 'remember' the&amp;nbsp;location and size of forms when they are closed, so that the next time they are shown, they can be restored to the&amp;nbsp;former position. The &lt;A href="http://msdn2.microsoft.com/library/0zszyc6e(en-us,VS.80).aspx"&gt;Application Settings&lt;/A&gt; feature is .NET 2.0 makes it simple to do this, but unfortunately, it is a little hard to get it 'just right'. This question is asked frequently on internal and external Microsoft forums, so I thought it warranted a blog post.&lt;/P&gt;
&lt;P&gt;Now, the Windows Forms designer in Visual Studio 2005 provides a simple UI to data bind properties on controls to application settings. So the first thing that might occur to you is to simply bind the Form's Location and Size properties to settings, add a line of code to save the settings class, and that's it! Unfortunately, this is not the best option for a few reasons:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;First of all, you may notice that the Form.Size property is not offered up in the settings binding UI. This is because this property is marked &lt;A href="http://msdn2.microsoft.com/en-us/library/system.componentmodel.designerserializationvisibility.aspx"&gt;DesignerSerializationVisibility.Hidden,&lt;/A&gt; so the designer doesn't know how to serialize it, let alone generate a data binding for it. Instead, for Form, the ClientSize property is the one that gets serialized. 
&lt;LI&gt;So okay, maybe you can bind Location and ClientSize then? Well, yes, but this has another problem. Try setting it up and then attempt to resize the form from the left or top edge. You will see weird behavior. Why is this? It is beyond the scope of this post to give the full explanation, but it suffices to say that it has to do with how two way data binding works&amp;nbsp;in the context of property sets that mutually affect each other (in the case of Location and ClientSize, both eventually call into a common method, &lt;A href="http://msdn2.microsoft.com/library/system.windows.forms.control.setboundscore.aspx"&gt;SetBoundsCore()&lt;/A&gt;). 
&lt;LI&gt;This solution does not do the 'right' thing in the situation when the user maximized the form before closing it. In this case, you probably want to remember that the form was maximized, but also keep track of the last location/size &lt;EM&gt;before&lt;/EM&gt; it was maximized, so you can restore it the next time the user hits the Restore button. You may want to handle the minimize case in a similar way too. The simple data binding solution does not do this right. 
&lt;LI&gt;Data binding to properties like Location and Size is just not efficient. Each time the user moves the form or resizes it, Windows sends hundreds of messages to the form, causing the&amp;nbsp; data binding logic to do a lot of processing, when all you want is just to store the &lt;EM&gt;last&lt;/EM&gt; position and size before the form is closed.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;The good news is that this is very easy to do with a few lines of code:&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P dir=ltr style="MARGIN-RIGHT: 0px"&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;private &lt;FONT color=#0000ff&gt;void&lt;/FONT&gt; Form1_FormClosing(&lt;FONT color=#0000ff&gt;object&lt;/FONT&gt; sender, &lt;FONT color=#008080&gt;FormClosingEventArgs&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt; e)&lt;BR&gt;{&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Properties.&lt;FONT color=#008080&gt;Settings&lt;/FONT&gt;.Default.MyState = &lt;FONT color=#0000ff&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;.WindowState;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#0000ff&gt;if&lt;/FONT&gt; (&lt;FONT color=#0000ff&gt;this&lt;/FONT&gt;.WindowState == &lt;FONT color=#008080&gt;FormWindowState&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;.Normal)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Properties.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#008080&gt;Settings&lt;/FONT&gt;.Default.MySize = &lt;FONT color=#0000ff&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;.Size;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Properties.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#008080&gt;Settings&lt;/FONT&gt;.Default.MyLoc = &lt;FONT color=#0000ff&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;.Location;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#0000ff&gt;&lt;FONT face="Courier New" size=2&gt;else&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Properties.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#008080&gt;Settings&lt;/FONT&gt;.Default.MySize = &lt;FONT color=#0000ff&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;.RestoreBounds.Size;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Properties.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#008080&gt;Settings&lt;/FONT&gt;.Default.MyLoc = &lt;FONT color=#0000ff&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;.RestoreBounds.Location;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;Properties.&lt;/FONT&gt;&lt;FONT face="Courier New" color=#008080&gt;Settings&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;.Default.Save();&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#0000ff&gt;private&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;void&lt;/FONT&gt; Form1_Load(&lt;FONT color=#0000ff&gt;object&lt;/FONT&gt; sender, &lt;FONT color=#008080&gt;EventArgs&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; e)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#0000ff&gt;this&lt;/FONT&gt;.Size = Properties.&lt;FONT color=#008080&gt;Settings&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;.Default.MySize;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#0000ff&gt;this&lt;/FONT&gt;.Location = Properties.&lt;FONT color=#008080&gt;Settings&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;.Default.MyLoc;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#0000ff&gt;this&lt;/FONT&gt;.WindowState = Properties.&lt;FONT color=#008080&gt;Settings&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;.Default.MyState;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;} &lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P dir=ltr&gt;By the way, speaking of Windows Forms 2.0, there is a lot of great &lt;A href="http://www.windowsforms.net/Default.aspx?tabindex=5&amp;amp;tabid=60"&gt;new content&lt;/A&gt; on the WindowsForms.net site. Jessica has been &lt;a href="http://blogs.msdn.com/jfoscoding/"&gt;actively blogging&lt;/A&gt; on interesting Windows Forms topics too.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=497792" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/rprabhu/archive/tags/Whidbey/default.aspx">Whidbey</category><category domain="http://blogs.msdn.com/rprabhu/archive/tags/Configuration_2F00_Settings/default.aspx">Configuration/Settings</category></item><item><title>Client Settings FAQ posted</title><link>http://blogs.msdn.com/rprabhu/archive/2005/06/29/434007.aspx</link><pubDate>Thu, 30 Jun 2005 01:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:434007</guid><dc:creator>rprabhu</dc:creator><slash:comments>68</slash:comments><comments>http://blogs.msdn.com/rprabhu/comments/434007.aspx</comments><wfw:commentRss>http://blogs.msdn.com/rprabhu/commentrss.aspx?PostID=434007</wfw:commentRss><description>&lt;P&gt;We have been getting lots of feedback on the new Whidbey Settings feature that I have &lt;a href="http://blogs.msdn.com/rprabhu/archive/category/6591.aspx"&gt;blogged about&lt;/A&gt; in the past.&amp;nbsp;Since there are a set of questions many people ask as they begin to delve into the API, I thought it might be useful to post an &lt;a href="http://blogs.msdn.com/rprabhu/articles/433979.aspx"&gt;FAQ&lt;/A&gt; that I can&amp;nbsp;point folks to that&amp;nbsp;should answer&amp;nbsp;most of these questions. I posted this as an article instead of a regular blog post so I can update it&amp;nbsp;off and on in the future.&lt;/P&gt;
&lt;P&gt;If you have any suggestions for questions to add to the FAQ, please feel free to leave a comment here.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=434007" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/rprabhu/archive/tags/Configuration_2F00_Settings/default.aspx">Configuration/Settings</category></item><item><title>Client Settings - Part 3</title><link>http://blogs.msdn.com/rprabhu/archive/2004/06/18/159404.aspx</link><pubDate>Fri, 18 Jun 2004 17:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:159404</guid><dc:creator>rprabhu</dc:creator><slash:comments>11</slash:comments><comments>http://blogs.msdn.com/rprabhu/comments/159404.aspx</comments><wfw:commentRss>http://blogs.msdn.com/rprabhu/commentrss.aspx?PostID=159404</wfw:commentRss><description>&lt;P&gt;RichB has some interesting questions in his &lt;A href="http://blogs.msdn.com/rprabhu/archive/2004/04/03/106996.aspx"&gt;comments&lt;/A&gt; about my earlier post on the client settings feature. I thought it might be worth a separate post to answer them.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;I don't have the CTP available, but from the documentation it appears that ApplicationSettingsBase can read and write to a collection of providers. I can understand the writing to multiple providers (saving the same values into multiple locations) but how does it read the same values from multiple locations. &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Yes, a settings class can&amp;nbsp;talk to&amp;nbsp;multiple providers, but each setting (or property) in it is associated with a single provider. This just means that you can have different providers for different settings in a settings class.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;I also hope you have a good "story" for plug-in based applications. For example, Lutz Roeder's Reflector and Nikhil's Web Matrix are both heavily pluggable. Is there a prescribed way for each plug-in/component to obtain and save configuration information to the same store? &lt;/EM&gt;&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;Yes, we have a story for this scenario. There is an interface called IPersistComponentSettings that any component can implement to save its own settings when hosted in an application. For example, the ToolStrip control implements this. Someone using the ToolStrip in their app can just set a property called SaveSettings to true and the ToolStrip will save/restore settings automatically without the user having to set anything up.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;I'm also a bit hazy on Setting Groups. I've noticed the SettingsGroupNameAttribute - but am not entirely clear on how it's meant to be used. &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Usually, the settings class name is used to identify&amp;nbsp;your settings in the store. If you want them stored with a different name or share settings with some other class, you can use the SettingsGroupNameAttribute to rename/redirect your settings.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Finally, do you have generic methods for loading from the store to prevent boxing?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;No, but that's a good suggestion. We will consider doing this.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=159404" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/rprabhu/archive/tags/Whidbey/default.aspx">Whidbey</category><category domain="http://blogs.msdn.com/rprabhu/archive/tags/Configuration_2F00_Settings/default.aspx">Configuration/Settings</category></item><item><title>Client Settings - Part 2</title><link>http://blogs.msdn.com/rprabhu/archive/2004/04/03/106996.aspx</link><pubDate>Sat, 03 Apr 2004 08:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:106996</guid><dc:creator>rprabhu</dc:creator><slash:comments>26</slash:comments><comments>http://blogs.msdn.com/rprabhu/comments/106996.aspx</comments><wfw:commentRss>http://blogs.msdn.com/rprabhu/commentrss.aspx?PostID=106996</wfw:commentRss><description>&lt;P&gt;In a &lt;A href="http://blogs.msdn.com/rprabhu/archive/2003/11/21/56556.aspx"&gt;post&lt;/A&gt; a few months ago, I wrote about a new Whidbey feature called Client Settings. While we briefly described this feature at the PDC, it wasn't available in the build of Whidbey released then. The &lt;A href="http://msdn.microsoft.com/vs2005/"&gt;Community Preview&lt;/A&gt; build gives you a chance to try out everything I mentioned and more. &lt;/P&gt;
&lt;P&gt;Quite some&amp;nbsp;functionality has been added to this feature since the PDC. I list some of the new capabilities below. If you haven't read my previous &lt;A href="http://blogs.msdn.com/rprabhu/archive/2003/11/21/56556.aspx"&gt;post&lt;/A&gt;, please read that first for background.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;[Caveat: Not all this may work very well in the recently released Community Preview&amp;nbsp;build]&lt;/EM&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;First of all, we now provide full fledged design time support in Visual Studio for you to easily create some settings and bind to them.&amp;nbsp;As a simple example, lets say you want to provide&amp;nbsp;the&amp;nbsp;user of&amp;nbsp;your app the ability to customize&amp;nbsp;the BackColor of a&amp;nbsp;Form, and you want to save their setting, so that when they run the app again, you can restore their preference. All you need to do is this: in the Form designer in Visual Studio, you will notice a new property in the property browser named &amp;#8220;(Application Settings)&amp;#8221;. This allows you to create a setting (in this case, user scoped) and set up a binding to a&amp;nbsp;property in a manner very similar to setting up data bindings. In the background, the Settings Designer will create a class for you that derives from ApplicationSettingsBase that has a property corresponding to the setting you just created. And the Forms Designer will generate the code to data bind that setting to your BackColor property. All you need to do now is to call Save() on your settings object - say, in the Form's Closing event. This line, in VB, will look something like: &lt;/LI&gt;&lt;/UL&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;My.Settings.Save()&lt;/P&gt;
&lt;P&gt;That's it! You now have everything setup to save each user's preference for BackColor of the Form. &lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;UL&gt;
&lt;LI&gt;The Settings Designer itself is another place&amp;nbsp;you&amp;nbsp;can start to create settings. In a VB project, the settings designer is offered as a tab in the Application Designer. In C#, you should be able get to it in a similar manner in a future build. The designer has simple UI to create settings and assign default values to them. It will generate the code&amp;nbsp;for the settings class and its properties, with appropriate attributes specified. 
&lt;P&gt;&lt;/P&gt;
&lt;LI&gt;ApplicationSettingsBase offers a bunch of new functionality. It has events that are fired when a setting's value changes, or when settings are saved (i.e., passed down to the provider). You can use these to do validation for example. It also provides methods to reset the settings to their default values and&amp;nbsp;upgrade settings from a previous version of the settings class. 
&lt;P&gt;&lt;/P&gt;
&lt;LI&gt;We also provide the ability for components to store their own settings, in a manner transparent to the host, through an interface called IPersistComponentSettings. The ToolStrip is an example of a control that implements this interface. If you drop a ToolStrip on your Form, you will notice a boolean property called 'SaveSettings'. Just set this to true, and the ToolStrip will automatically&amp;nbsp;begin to store its own settings - like which rafting container it is placed in and what its location is within the container. ToolStrip items too can store out settings of their own. All this happens transparently - a ToolStrip user doesn't need to setup anything - just set SaveSettings to true! You can provide this same functionality for your component/control just by implementing IPersistComponentSettings. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;So you may be wondering - where are these settings stored? That really depends on the settings provider you are using. The default settings provider that ships in Whidbey is called the LocalFileSettingsProvider. This stores all the settings in configuration files. One of the other things the Settings Designer described above does for you is put the required entries&amp;nbsp;in the application config file, where&amp;nbsp;our provider stores application scoped settings, and default values for user scoped settings.&amp;nbsp;&amp;nbsp;In .Net Framework v1.1, there were two levels of configuration files - machine and application. In Whidbey, we have introduced the concept of user specific config files, that are stored under the user's profile path. These config files are created when a user saves their preferences, and contain the values that differ from the defaults.&lt;/P&gt;
&lt;P&gt;Anyway, that's just an overview of some of the new functionality we have added since the PDC. If you are using the feature, do let us know what you think!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=106996" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/rprabhu/archive/tags/Whidbey/default.aspx">Whidbey</category><category domain="http://blogs.msdn.com/rprabhu/archive/tags/Configuration_2F00_Settings/default.aspx">Configuration/Settings</category></item><item><title>Feature Preview: Client Settings</title><link>http://blogs.msdn.com/rprabhu/archive/2003/11/21/56556.aspx</link><pubDate>Fri, 21 Nov 2003 14:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:56556</guid><dc:creator>rprabhu</dc:creator><slash:comments>17</slash:comments><comments>http://blogs.msdn.com/rprabhu/comments/56556.aspx</comments><wfw:commentRss>http://blogs.msdn.com/rprabhu/commentrss.aspx?PostID=56556</wfw:commentRss><description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;
    &lt;p&gt;
        One of the new Whidbey features Joe Stegman &lt;a href="http://www.vsdotnet.be/blogs/tommer/PermaLink.aspx?guid=260b0e73-9a6c-4b07-a131-f44f690e881f"&gt;talked&lt;/a&gt;&amp;#160;about
        at the PDC was Client Settings. This is a feature I have spent a lot of&amp;#160;time
        on in Whidbey, so I thought I would talk a little bit about it. 
    &lt;/p&gt;
    &lt;p&gt;
        Very often, if you are writing a client app (also for web apps, but let me focus on
        client for now), you need&amp;#160;the ability to store some settings. These settings
        are often user preferences, like Form size and location,&amp;#160;look and feel&amp;#160;of
        various controls, toolbar positions, last read entry etc.&amp;#160;etc.&amp;#160;These could
        also be more application specific things like connection strings and resource paths.&amp;#160;In
        .NET Framework v1.0 and v1.1, there are&amp;#160;several ways to achieve this - using &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vboriintroductiontoapplicationsettingstorage.asp"&gt;dynamic
        properties&lt;/a&gt;, writing your own &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconconfigurationsectionhandlers.asp"&gt;configuration
        section &lt;/a&gt;to store stuff into the application config file or storing the settings
        in a separate file, possibly in XML format, and parsing the content yourself. Ofcourse,
        then there is the traditional store for application settings - the Windows registry. 
    &lt;/p&gt;
    &lt;p&gt;
        Each of these, however, has some limitations. Dynamic properties support a limited
        range of types and are read only. Writing a configuration section isn't very easy
        - you need to do all the parsing, merging between levels&amp;#160;and validation yourself.
        Storing settings into an independent file means you need to management the deployment
        of that file yourself, besides, ofcourse, having to do&amp;#160;the parsing, defining
        what schema to use and so on. The registry too isn't the right place to store settings
        in many cases. 
    &lt;/p&gt;
    &lt;p&gt;
        So, if you want to store settings today, you need to put in considerable effort to
        do it right. The &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/cmab.asp"&gt;Configuration
        Management Application Block&lt;/a&gt; solves some of these problems for you today, and
        is pretty cool, but in Whidbey, we are taking a big step forward and&amp;#160;are trying
        to design a model which makes it super easy to consume settings in your application.
        What's more, the core parts of this model are common to web and client apps, so there
        is more consistency in how you store and access settings across different kinds of
        applications. 
    &lt;/p&gt;
    &lt;p&gt;
        At the core of the new settings infrastructure are two abstract classes - SettingsBase
        and SettingsProvider. SettingsBase hides the storage details way from the application
        developer and exposes an easy mechanism to read, write and save settings. The SettingsProvider
        is actually responsible for persisting these settings. How it persists them is its
        own choice - SettingsBase doesn't really care. It could store them in a local file,&amp;#160;a
        database or&amp;#160;retrieve them through a web service, for example. In each case, the
        way the application&amp;#160;consumes the settings remains the same. 
    &lt;/p&gt;
    &lt;p&gt;
        The ApplicationSettingsBase class Joe talked about adds value to SettingsBase and
        makes it even more easier to create your own&amp;#160;settings. Essentially, in this model,
        settings are nothing but properties on classes that are decorated with a bunch of
        attributes that describe them. 
    &lt;/p&gt;
    &lt;p&gt;
        Here is a how a simple settings class would look: 
    &lt;/p&gt;
    &lt;font size="2" face="Courier New"&gt; 
    &lt;p&gt;
        public class MySettings : ApplicationSettingsBase { 
        &lt;br /&gt;
        &amp;#160;&amp;#160;&amp;#160;[UserScopedSetting]&amp;#160; // varies by user 
        &lt;br /&gt;
        &amp;#160;&amp;#160; [DefaultSettingValue("Blue")]&amp;#160; // use this if no value is stored 
        &lt;br /&gt;
        &amp;#160;&amp;#160; public Color MyFormColor {&amp;#160; 
        &lt;br /&gt;
        &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;get { 
        &lt;br /&gt;
        &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;return
        (Color) this["MyFormColor"]; 
        &lt;br /&gt;
        &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 
        &lt;br /&gt;
        &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; set { 
        &lt;br /&gt;
        &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this["MyFormColor"]
        = value; 
        &lt;br /&gt;
        &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 
        &lt;br /&gt;
        &amp;#160;&amp;#160; } 
        &lt;br /&gt;
        &lt;br /&gt;
        &amp;#160;&amp;#160; [ApplicationScopedSetting] //shared&amp;#160;by all&amp;#160;users 
        &lt;br /&gt;
        &amp;#160;&amp;#160; [SettingsProvider("MyWebServiceProvider.blahblah")] 
        &lt;br /&gt;
        &amp;#160;&amp;#160; public Point FooLocation { 
        &lt;br /&gt;
        &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;get { 
        &lt;br /&gt;
        &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;return
        (Point) this["FooLocation"]; 
        &lt;br /&gt;
        &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 
        &lt;br /&gt;
        &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; set { 
        &lt;br /&gt;
        &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this["FooLocation"]
        = value; 
        &lt;br /&gt;
        &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 
        &lt;br /&gt;
        &amp;#160;&amp;#160; } 
        &lt;br /&gt;
        } 
        &lt;br /&gt;
    &lt;/p&gt;
    &lt;/font&gt; 
    &lt;p&gt;
        and then consuming these settings is equally staightforward: 
    &lt;/p&gt;
    &lt;font size="2" face="Courier New"&gt; 
    &lt;p&gt;
        myForm1.BackColor = MySettings.MyFormColor; 
        &lt;br /&gt;
        ... 
        &lt;br /&gt;
        MySettings.FooLocation = myControl1.Location; 
        &lt;br /&gt;
        ... 
        &lt;br /&gt;
        MySettings.Save(); 
        &lt;br /&gt;
    &lt;/p&gt;
    &lt;/font&gt; 
    &lt;p&gt;
        Its as simple as that! You can read/write settings of arbitrary types (which the provider&amp;#160;can
        serialize, ofcourse) with just a few simple lines of code. By default, for client
        apps, we will ship a provider that can store settings into the application configuration
        files (we are extending the configuration system to store user specific stuff too)
        without any extra effort on the application developer's part! 
    &lt;/p&gt;
    &lt;p&gt;
        That's not it, though. This model is also powerful for those who have more requirements.
        You can write your own custom provider that stores settings wherever it wants. You
        can exercise more control over how the default provider serializes its settings. You
        can define your own attributes that only your provider understands - ApplicationSettingsBase
        will pass the metadata over to the provider. You can group your settings into a bunch
        of different classes, map settings to different providers, bind the settings to properties
        of your UI/business objects through data binding and so on and so forth. If you wish
        to write your own configuration section, the ASP.NET team has made that much easier
        too. 
    &lt;/p&gt;
    &lt;p&gt;
        That's not all we have planned - there is more, including great design time support
        in Visual Studio and&amp;#160;the concept of component settings. 
    &lt;/p&gt;
    &lt;p&gt;
        More on all this&amp;#160;as we approach&amp;#160;Whidbey&amp;#160;Beta! 
    &lt;/p&gt;
    &lt;/font&gt;&lt;/font&gt;
&lt;/body&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=56556" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/rprabhu/archive/tags/Whidbey/default.aspx">Whidbey</category><category domain="http://blogs.msdn.com/rprabhu/archive/tags/Configuration_2F00_Settings/default.aspx">Configuration/Settings</category></item></channel></rss>