共用方式為


Managing SharePoint Configuration

This section describes how configuration information is stored in SharePoint.

Hierarchical Object Store

The hierarchical object store is the mechanism by which Windows SharePoint Services stores information about the farm, Web applications, features, and so on. You can use it to store custom configuration data by creating classes that inherit from the SPPersistedObject class. This option is appropriate if you need to store complex objects. The hierarchical object store allows you to store data at either the farm or Web application level. Additionally, you can create a custom hierarchy of SPPersistedObjects rooted by an instance of SPFarm or SPWebApplication.

Property Bags

A property bag enables you to add and retrieve properties to objects. Property bags are implemented as a simple hash table of property names and values. Do not attempt to store anything in property bags unless you are sure it can be serialized.

At the site level, a property bag can be accessed with the Properties property of an instance of the SPWeb class. If you want to store list-level configuration data, use the property bag of the root folder of the list.

You can use a property bag to store configuration information at different levels of the SharePoint hierarchy. The following table summarizes the options.

Level

Storage location

SPFarm

The Properties property that is inherited from the SPPersistedObject class.

SPWebApplication

The Properties property that is inherited from the SPPersistedObject class.

SPSite

The AllProperties property of the root Web.

SPWeb

The AllProperties property.

SPList

The RootFolder.Properties property.

Make sure to use prefixes with your keys to help you distinguish your custom configuration properties from other properties. In particular, be careful not to remove properties that are added by SharePoint. You must call the Update method when you add, change, or remove a property bag entry.

Lists

Use lists if you want to store configuration data that end users can edit. Otherwise, consider using property bags. Lists can also be used as a way of storing configuration data at different levels of the SharePoint hierarchy. The following table summarizes the options.

Level

Storage location

SPFarm

List in Central Administration site or subsite.

SPSite

List in the root Web of the site collection.

SPWeb

List in the SPWeb

More Information

To learn more about using the Web.config file to store configuration data, see Working with Web.config Files on MSDN.

There is a tool named Web.config Modification Manager for SharePoint that you can use to add, edit, and delete modifications to the Web.config file made through the SPWebConfigModification API. This tool was created by Vincent Rothwell and is available on his blog.

Home page on MSDN | Community site