Introduction to WSSv3 OM

Hey folks, as promised--we have hit the Beta2 mark, so here come the blogs again. I have had the opportunity to work with many of you in our private TAP and Beta programs, which I have enjoyed very much. I hope to initially share some of the knowledge that I gained during this experience with the rest of you. First--I want to provide you with what I would consider to be some important links. If you have questions on something I discuss here, I would ask that you look in these sources first before posting. Here's the links:

1st, get the Beta:
2nd, get the WSSv3 SDK:
3rd, get the MOSS SDK+Samples:
4th, get the MOSS ECM Starter Kit (this includes workflows):
5th, get the Project SDK+Samples (this is not an area I'll be talking about, but wanted to provide the link):

It is worth pointing out that so far in SharePoint 2007, I have had focus on Workflow, Content Types, Features, general administration, and obviously... the OM. Do keep in mind that I also have spent some time familiarizing myself with the differences on using VS2005 and the current extensions in windbg for debugging in a SharePoint 2007 environment.

So, lets get on with it. For our first code sample--I want to point out one of the most obviously OM changes that you just simply "need" to know about. We are planning to mark the following WSS classes as Obsolete:




I need to stress here that we fully intend to keep these classes working and backwards compatible with code written against WSSv2. This is simply to enforce that we have a new object model that you should be using in your new code moving forward. So as a part of that effort, I am going to re-demonstrate how to accomplish some of the common tasks but using the new object model.

Here is some code to do some basic enumeration. This would in a sense get you into the areas that are mentioned above and then some. This also of course can get you into what might before only be in the topology manager (via SPFarm.Servers) and other areas that I'm sure you will figure out as you start to play.

In order to get this code to work, you simply need a new c# project. Add a reference to Microsoft.SharePoint (its the third one from the bottom in the browser), and then add:

using Microsoft.SharePoint;

using Microsoft.SharePoint.Administration; //For SPFarm, SPServerCollection, SPWebApplicationCollection

Then just give yourself a button or something and run this code:

SPFarm mySPFarm = SPWebService.ContentService.Farm;

SPServerCollection mySPServerCollection = mySPFarm.Servers;

SPWebApplicationCollection mySPWebAppCollection = SPWebService.ContentService.WebApplications;

if (mySPWebAppCollection != null)


    foreach (SPWebApplication mySPWebApp in mySPWebAppCollection)


        Console.WriteLine("WebApplication: " + mySPWebApp.Name);

        Console.WriteLine(" AppPool: " + mySPWebApp.ApplicationPool.Name + " (" + mySPWebApp.ApplicationPool.Status + ")");

        SPContentDatabaseCollection mySPContentDBCollection = mySPWebApp.ContentDatabases;

        Console.WriteLine(" # Content DBs: " + mySPContentDBCollection.Count);

        foreach (SPContentDatabase mySPContentDB in mySPContentDBCollection)


            Console.WriteLine(" Database Name: " + mySPContentDB.Name);

            Console.WriteLine(" Database Server: " + mySPContentDB.Server);

            Console.WriteLine(" DSN: " + mySPContentDB.DatabaseConnectionString);




Obviously, if you know a specific URL, you're going to still use SPSite in some fashion to get directly to a SPSite or SPWeb object. Hopefully this will get you started into some of the higher level objects in WSSv3.