Introduction to SharePoint Object Model

No.of Views1295
Bookmarked0 times
Downloads 
Votes0
By  Ravish Kumar Sindhwani   On  11 Jun 2010 21:06:51
Tag : SharePoint , Development and Programming
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
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

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

Image Loading

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

Image Loading

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 Meetings

Image Loading

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. Sites

Image Loading

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.Solutions

Image Loading

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 Lists

Image Loading

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  User Profile

Image Loading

8 Business Data Catalog

Image Loading

Conclusion

This is all about Sharepoint Object Model.i hope this is help to you all.

 
Sign Up to vote for this article
 
About Author
 
Ravish Kumar Sindhwani
Occupation-Software Engineer
Company-
Member Type-Fresh
Location-India
Joined date-11 Jun 2010
Home Page-
Blog Page-
I born and brought up in Haryana and working as a software developer in Trivandrum. I am passionate for learning new Microsoft technologies and I believe if you are learning any new thing, just write it some where. You will never forget.
 
 
Other popularSectionarticles
Comments
By:Introduction to SharePoint ObjDate Of Posted:3/27/2011 2:07:48 AM
Introduction to SharePoint Object Model
Microsoft SharePoint Foundation offers a highly structured server-side object model that makes it easy to access objects that represent the various aspects of a SharePoint Web site. From higher-level objects, you can drill down through the object hierarchy to obtain the object that contains the members you need to use in your code.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top