Update: Release 22.214.171.124 uploaded 03 Sept 2009 - see Release 126.96.36.199 page for release notes
The SharePoint Config Store is intended for SharePoint developers, and provides the framework to be able to use a SharePoint list for application configuration values. This is useful when there are certain values used in a site or application's code, but
we don't to hardcode them or even store them in web.config. Storing such values in a list means they can be easily updated (possibly by end users if you choose to allow this) without requiring access to the web server's filesystem.
Example config items for a SharePoint site/application/control could be:
'AdministratorEmail' - 'email@example.com'
'SendWorkflowEmails' - 'true'
The Config Store is also highly-optimized, and so offers more than just a simple implementation of just retrieving values from a list.
The list used to store config items looks like this (N.B. the items shown are my examples, you'd add your own):
There is a special content type associated with the list, so adding a new item is easy:
..and the content type is defined so that all the required fields are mandatory:
Once a value has been added to the Config Store, it can be retrieved in code as follows (you'll also need to add a reference to the Config Store assembly and 'using' statement of course):
string sAdminEmail = ConfigStore.GetValue("MyApplication", "AdminEmail");
Note that there is also a method to retrieve multiple
values with a single query. This avoids the need to perform multiple queries so should be used for performance reasons if your control/page will retrieve
items from the Config Store - think of it as a best practise. The code is slightly more involved, but should make sense when you think it through. We create a generic List of 'ConfigIdentifiers' (a ConfigIdentifier specifies the category
and name of the item e.g. 'MyApplication', 'AdminEmail') and pass it to the 'GetMultipleItems()' method:
List<ConfigIdentifier> configIds = new List<ConfigIdentifier>();
ConfigIdentifier adminEmail = new ConfigIdentifier("MyApplication", "AdminEmail");
ConfigIdentifier sendMails = new ConfigIdentifier("MyApplication", "SendWorkflowEmails");
Dictionary<ConfigIdentifier, string> configItems = ConfigStore.GetMultipleValues(configIds);
string sAdminEmail = configItems[adminEmail];
string sSendMails = configItems[sendMails];
..the method returns a generic Dictionary containing the values, and we retrieve each one by passing the respective ConfigIdentifier we created earlier to the indexer.
- All items are wrapped up in a Solution/Feature so there is no need to manually create site columns/content types/the Config Store list etc. There is also an install script for you to easily install the Solution.
- Config items are cached in memory, so where possible there won't even be a database lookup!
- The Config Store is also designed to operate where no SPContext is present e.g. a list event receiver. In this scenario, it will look for values in your SharePoint web application's web.config file to establish the URL for the site containing the Config
Store (N.B. these web.config keys get automatically added when the Config Store is installed to your site). This also means it can be used outside your SharePoint application, e.g. a console app.
- The Config Store can be moved from it's default location of the root web for your site. For example my sites usually have a hidden 'config' web, so I put the Config Store in here, along with other items. (To do this, create a new list (in whatever
child web you want) from the 'Configuration Store list' template (added during the install), and modify the 'ConfigWebName'/'ConfigListName' keys which were added to your web.config to point to the new location. As an alternative if
you already added 100 items which you don't want to recreate, you could use my other tool, the SharePoint Content Deployment Wizard at
http://www.codeplex.com/SPDeploymentWizard to move the list.)
- All source code and Solution/Feature files are included, so if you want to change anything, you can
- Installation instructions are in the readme.txt in the download
Hope you find it useful, all feedback welcome!