Introduction to SharePoint Object Model


HTML clipboard

There are several namespaces(around 50) that house the SharePoint object model. Out of these 50 namespaces we are using only 16 namespaces, rest of the namespaces are reserved for Microsoft internal use.

1. Document Library

image1.gif

Document libraries are a special type of list designed to store documents.To access a document library through object model we need to use Microsoft.Sharepoint namespace. To use this namespace in ASP.net we need to add a reference of Microsoft.Sharepoint.dll. This dll we can find from the below mentioned path:

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI

Let's take each and every class in this namespace:

  • SPDocumentLibrary Class:

    This class represents a document library in Windows Sharepoint Services.
    In C# code: SPDocumentLibrary obj = (DocumentLibrary)oList
    oList is an object for list. The above code will cast the list object into Document Library.

  •  
  • SPPictureLibrary Class:

    This class represents a picture library in Windows Sharepoint Services. Both classes are used in the sane manner. The only difference is: As the name indicates SPDocumentLibrary is used for Document Library and SPPictureLibrary is used for Picture Library.
2. Features:

image2.gif

For using the features through Sharepoint object model we need Microsoft.Sharepoint dll and you can get the dll from the above mentioned path.
  • SPFeatureDefinition Class: Contains the base definition of an SPFeature, including its name, identifier, scope, and version
  • SPFeatureScope Class : Specifies the scope to which the feature applies.
  • SPElementDefinition Class: Serves as the base class for implementing element types within Windows SharePoint Services
  • SPFeature Class: Represents the state of a feature at its corresponding scope
  • SPFeatureProperty Class: Represents a single Feature property.
Code Example:

SPSite oSpSite = new SPSite("http://YourServer");
SPFeatureCollection oSPfeatureCollection = oSpSite.Features;

foreach (SPFeature oSPFeature in oSPfeatureCollection)
{
    SPFeatureDefinition featureDefinition = oSPFeature.Definition;
    SPElementDefinitionCollection elementDefinitionCollection =
featureDefinition.GetElementDefinitions(System.Globalization.CultureInfo.InvariantCulture);

    foreach (SPElementDefinition elementDefinition in elementDefinitionCollection)
    {
        Console.WriteLine(elementDefinition.Id);
    }
}

Ref: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfeatureproperty.aspx

3.

image3.gif

For using meetings through object model we need to add Microsoft.Sharepoint dll as mentioned above. The classes under this category are explained as below:

SPMeeting Class:- Provides methods and properties that can be used to work with a Meeting Workspace. Suppose if you want to create a meeting workspace through object model then we need to use this class. There are different kind of meeting template that can be handled like Basic meeting, Decision Meeting, Multiple meeting etc.

MtgUtility:- Initialize a new instance of the MtgUtility class. To access the MtgUtility service and its methods, set a Web reference to http://Server_Name/[sites/][Site_Name/]_vti_bin/xxx.asmx

Microsoft.SharePoint.Meetings.MtgUtility – System.Object

4.

image4.gif

Sites objects are used to access the sharepoint site, The classes under this category of Sharepoint Object model are explained as below:

SPSite: . Represents a collection of sites in a Web application, including a top-level Web site and all its subsites. Each SPSite object, or site collection, is represented within an SPSiteCollection object that consists of the collection of all site collections in the Web application.

SPWeb: Represents a Windows SharePoint Services Web site.

CODE Example:

using(SPSite oSite = new SPSite("http://Server_Name"))
{
    using(SPWeb oWebsite = oSite.OpenWeb("Website_URL"))
    {
        using(SPWeb oWebsiteRoot = oSite.RootWeb)
        {
           ...//Your Code
        }
    }
}

5.

image5.gif

Provides administrative types and members for managing a Windows SharePoint Services deployment. There are so many classes, delegates, interface under this namespace but only few classes I am going to explain.

SPSolution : Represents a solution on a farm.

Namespace: Microsoft.SharePoint.Administration

Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)

SPFeatureReceiver:

Base abstract class that can be overridden to trap the activation, deactivation, installation, or uninstallation of a Feature.

Namespace: Microsoft.SharePoint

Assembly: Microsoft.SharePoint

Use the SPFeatureReceiver class to trap events that are raised after the Feature installation, uninstallation, activation, or deactivation action has been performed.

It is not possible to cancel an installation or uninstallation through Feature events.

SPSolutionCollector:

Represents a collection of SPSolution objects.

Namespace: Microsoft.SharePoint.Administration

Assembly: Microsoft.SharePoint

6.

image6.gif

SPList object represent a List, SPListItem represent a List Item in the List and SPListItemCollection object represent a full item collection in the SPLIST.

Code Example:

SPList mylist_Name = myweb.Lists["Category"];
SPListItemCollection itmcln = mylist_Name.Items;
foreach (SPListItem itm in itmcln)
{
if (itm["ItemCategory"] != null)
{
ddlCategory.Items.Add(itm["ItemCategory"].ToString());

}
}

7.

image7.gif

8.

image8.gif

This is all about Sharepoint Object Model.