Intro to SharePoint: Data Lists
August 12, 2008
In continuation of the Intro to SharePoint webcasts that I’ve been watching, here are my notes from the second one, which introduces Data Lists. The entire collection of webcasts can be found here.
Speaker:
Robert Bogue
Microsoft MVP for MOSS
Thor Projects LLC
SharePoint is a virtual file system, which is stored in a content database.
SHAREPOINT LISTS
A SharePoint list is essentially a table in Sql Server. They can have their own form pages and multiple SharePoint views (with grouping, etc). They are created from templates (Example: Creating a list of type “Contacts”), which can then be modified. Lists can contain one or more Content Types, which are a way to encapsulate the metadata and processes about something. (Content Types are one or the most powerful tools in SharePoint). Lists can have attachments.
DOCUMENT LIBRARIES
A document library is a special type of list, that has one and only one attachment all the time.
PROGRAMMING WITH LISTS
The Object model is located in namespace Microsoft.SharePoint.dll (there are several more subsets). You can access the OM from any server in the farm (the Web front-end or the application server). The OM can only touch other sites and apps in the same web farm.
SERVER AND SITE ARCHITECTURE
-
Top level object: SP Farm – lets you know what servers are in the farm, what web apps are being hosted by the farm
-
SPServer: Web front-end, index server, etc
-
SPWebApplication: Usually you have web application on multiple servers, or you can have more than one web app on each server
-
SPSite: Site collections, a boundary for backup, queries. This is an important object. This is normally the highest level you go to during development
-
SPWeb: A collection of these are in the SPSite. In these, you have a List property (used to access Lists and Document libraries)
-
SPList/SPDocumentLibarary
-
SPListItem and SPField
CREATING LIST ITEMS
Use the SPListItem object. Be sure to use internal names (SharePoint gives an internal name when it is first created. It is the name of the field minus any special characters.)
IMPORTING DATA
There is a generally accepted rule (soft rule) of including up to 2000 rows to comfortably keep performance up. However, in one of Rob’s examples, he uploads 18,000 records, which SharePoint can handle, usually under 3 minutes.
RETRIEVING LIST ITEMS
Use SPListItemCollection/SPListItem. There are three main ways to handle this:
-
Loop over all objects in SPList.Items collection
-
Use databinding with GetDataTable method
-
Execute a query against the list (in CAML-Collaborative Application Markup Language)
QUERYING DATA IN CAML
CAML queries can be executed against one or more list instances. When executing a CAML query, use either SPQuery, SPSiteDataQuery, or Lists.asmx. There are some tools out there that help you build CAML queries
WORKING WITH DOCUMENTS
There are a few things that a document library can do that a List cannot:
- SPFile.CopyTo – makes a copy of the document in another document library in the same site
- SPFolder.Files.Add – adds a document
- SPFile.MoveTo – moves document, metadata, and versions from one document library to another
SUMMARY
Microsoft.SharePoint.dll is a powerful API for creating and managing the containers and all of its content.
Possible hosts for your code are WinForms apps running on the machine of SharePoint products and technologies, and SharePoint solution components like Web Parts, application, and site pages.