In a layer model ASP.NET builds the UI Layer (and also the service facade), the SharePoint Object Model is the business layer and for sure there is also a data access layer. The data access layer is the dark side of SharePoint, because it’s mainly unmanaged. It’s a mixture of unmanaged code and T-SQL. Unfortunately the unmanaged part isn’t under the control of the developer and vulnerable for memory leaks. What you can do is query (only read!) the database with SQL directly, but isn’t that intuitive and not recommended. There are unverified stories that with SharePoint 14 there will be a one to one relation between SharePoint lists and database tables – we will see. To cut a long story short, the way of choice to interact with the SharePoint database is the object model.
The SharePoint object model is simply a beauty. I felt in love with it since I used it the first time about 6 years ago.
SharePoint Object Hierarchy Overview
Example – From Farm to List Item
Here is an example for beginners how to traverse from SPFarm to SPListItem. The objects used in this example can be found in two namespaces. From SPFarm to SPWebApplication in Microsoft.SharePoint.Administratation, from SPSite to SPListItem in Microsoft.SharePoint. The Namespaces resides both in the Microsoft.SharePoint.dll at “%commonprogramfiles%\Microsoft Shared\web server extensions\12\ISAPI”. Any clue where you will find it in SharePoint 14 ;-)
Always keep in mind that the object model is not remotable and have to run on the SharePoint server!
Console.ForegroundColor = ConsoleColor.Green;
Console.BufferHeight = 1000;
//Get local farm
SPFarm farm = SPFarm.Local;
foreach (SPService service in farm.Services)
if (service is SPWebService)
SPWebService webService = (SPWebService)service;
foreach (SPWebApplication webApp in webService.WebApplications)
//Loop Site Collections
foreach (SPSite site in webApp.Sites)
foreach (SPWeb web in site.AllWebs)
foreach (SPList list in web.Lists)
foreach (SPListItem item in list.Items)