Building Block: Lists and Document Libraries
Published: May 2010
Microsoft SharePoint Foundation 2010 offers several APIs that you can use to work with lists. The following managed object models provide types and members that allow you to modify list properties and create and manage list templates and list items:
For code that operates on the server, the Microsoft.SharePoint namespace provides the core classes that represent a list. The Microsoft.SharePoint.Deployment namespace provides an API for migrating content between site collections.
For managed code that operates in the context of client-side Microsoft .NET 3.5 applications or Silverlight applications, the Microsoft.SharePoint.Client namespace provides a subset of the types and members available in the server object model.
The Lists Web service provides methods for working remotely with lists.
You can use the SaveAsTemplate(String, String, String, Boolean) method in the server-side object model to save an existing SharePoint Foundation list as a list template, or use the SPListTemplate class and its collection class to manage list templates. The SPListTemplate class represents both custom list templates, which you create through the SaveAsTemplate(String, String, String, Boolean) method or save through the UI, and list definitions, which you install and activate as a Feature in the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\FEATURES directory.
A list schema has both a base type and a list template type. The SPBaseType enumeration identifies the following list base types:
Generic list type for most lists
Unspecified base type.
The SPListTemplateType enumeration identifies the default list template types in SharePoint Foundation, each of which is associated with a single list base type definition. The SPList class provides access to list properties common to all lists, but it is also possible for list template types to derive from a list base type. For example, you can cast a list object that represents a document library as an SPDocumentLibrary object to access properties that are specific to document libraries.
Microsoft Microsoft Business Connectivity Services (BCS) provides APIs for working with external lists. For information about Business Connectivity Services, see Building Block: External Content Types and External Lists.
The following classes in the server and client object models can be used to work with lists, list templates, and list items:
SPListDataSource – Provides information about an external list.
SPListEventProperties – Provides properties for SharePoint list events.
SPListEventReceiver – Provides methods to trap events that occur for lists.
SPListItemVersion – Represents a version of a list item.
SPListTemplate – Represents a list definition or a list template, which defines the fields and views for a list. List definitions are contained in files within the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\FEATURES directory, but list templates are created through the user interface or through the object model when a list is saved as a template.
SPListTemplateType – An enumeration that specifies the type of a list definition or a list template.
SPBaseType – An enumeration that specifies the base type for a list.
SPDocTemplate – Represents a document template used in a document library.
SPDocumentLibrary – Represents a document library in SharePoint Foundation.
For information about working with lists in the server object model, see Working with List Objects and Collections and programming tasks included in Basic Object Model Tasks in SharePoint 2010. For information about working with lists in the client object models, see Data Retrieval Overview and programming tasks in Common Programming Tasks in the Managed Client Object Model.
A list definition is activated as a SharePoint Foundation Feature and has a Schema.xml file that contains the schema, although much of the view definition is provided through XSLT in the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\LAYOUTS\XSL directory. List is the top-level element in the list schema, but the Configuration element in a site definition schema also contains a List element to include a specific list as part of Web sites that are created through the site definition. The List Instance Feature allows you to specify default data with which to provision a list type. For information about how to use Features, see Using Features in SharePoint Foundation. For an example that shows how to create a list definition Feature, see How to: Create a Custom List Definition.