Core Foundation Assemblies
Excerpt by Doug Ware
Before you can write any managed code for SharePoint you must reference the assembly that contains the classes you need. Although there are many assemblies in a SharePoint installation, there are a few that you will use often. If you are using one of the SharePoint project templates in Visual Studio 2010, the appropriate references are usually preconfigured when you create the Visual Studio solution. The most commonly used assemblies are in the SharePoint root within the ISAPI folder although there are many located in other places, especially in the global assembly cache. Some of the most commonly used assemblies are:
- Microsoft.SharePoint: The core classes for SharePoint Foundation.
- Microsoft.SharePoint.Client: The core classes for client applications using the managed client object model.
- Microsoft.SharePoint.Linq: LINQ to SharePoint.
- Microsoft.SharePoint.WorkflowActions: SharePoint specific workflow actions.
Core ClassesThe classes that represent the elements common to all SharePoint sites are in the Microsoft.SharePoint assembly. Figure 15 shows a few of these classes. If you have taken the time to become familiar with SharePoint as a user, the purpose of most of these should be obvious to you at this point-SPSite is a site collection, SPWeb is a web, and so on.
Some of the commonly used classes in Microsoft.SharePoint.dll.
SPContextSPContext is the only class shown in figure above that doesn't represent an item in a SharePoint site. You use this extremely handy class when writing code that runs when SharePoint renders a page, for example in a Web Part or user control, to gain access to the current request. You can use SPContext . Current to get access to the current:
Common ConventionsAs you saw in Figure above, it is easy to guess the names of most of the core classes-just add an SP to the front of the name. For example, it should come as no surprise that the class you use to work with an alert is SPAlert! Other common conventions include:
- An item's name is usually the Title property such as SPWeb.Title and SPList.Title.
- Most collection indexers provide the following overloads for accessing collection items:
- Ordinal index
- Title (if applicable)
- Most changes to property changes only persist when you call the object instance's Update() method.