4
votes

I am making a Sharepoint 2010 WebPart with functionality from another Main Web Application. To develop the Webpart quickly I have imported the business logic assemblies used in the Main Web Application. The Webpart works and pulls application specific configuration information from the Sharepoint web.config file.

Is this the best place to store this information?

If not..

Where/How should the application specific configuration data be stored in Sharepoint?

The config data contains items like locations of web services etc. The data will only need to be edited by system administrators.

Thanks

3

3 Answers

5
votes

Web.Config is, IMHO, a terrible place to store this sort of config information - its hard to deploy and hard to change, especially if you're using multiple web front ends.

The recommended way to do this is to use PropertyBag (key/value pairs) through the .Properties of SPFarm, SPWeb.RootWeb (for site collections), SPWeb, SPList etc (depending upon the scope that you need).

MSDN - Managing Custom Configuration Options for a SharePoint Application

There is a production ready code available as part of the

MSDN - The SharePoint Guidance Library

See Hierarchical configuration manager

This gives you programmatic access to read/write these values. If you want to do this without using the guidance library then you would use something like the following code.

SPWeb web = SPContext.Current.Web;
if (web.Properties.ContainsKey("MyProperty"))
   string myProperty = web.Properties["MyProperty"];

If you want a UI to allow admins to easily set the values then use something like SharePoint Property Bag Settings

1
votes

The easiest way to do it is to create sharepoint list visible only to administrator. It can have 3 columns description, title, value. It will store all config values. Also you can add a link to this list to site settings page.

0
votes

The web config is always a good place. However if you want to change that data you will have to enforce some sort of site recompile which is a pain for end users.

Theres a nice little app/solution on codeplex to do with the property bag value

http://pbs.codeplex.com/

This is a brilliant little app/solution that ties in with your central administration.

It should be inbuilt i think.

Hope this helps.