Monday, January 17, 2011

Overview of SharePoint Object Model


Overview of SharePoint Object Model

SharePoint offers a set of structured server-side objects those are widely used to program SharePoint Applications. These objects are hierarchically arranged and you can drill down through the object hierarchy to obtain the object that contains the components of SharePoint Application you need to use in your code.

SharePoint object model can be grouped in two categories:
1. Object model of Server Architecture
2. Object model of Site Architecture

Object model of Server Architecture:
Following diagram shows the Windows SharePoint Services server architecture in relation to the SharePoint objects and collections. All these objects and collections are available in the “Microsoft.SharePoint.Administration” namespace.

SPFarm Object
SPFarm object is the highest object within the Windows SharePoint Services object model hierarchy which represents a WSS farm and used for central configuration settings. It contains global settings for all the servers, services, and solutions that are installed in a WSS farm. With this object you can also access all the servers, services, and solutions that are installed in a WSS farm.

· Create method can be used to a server farm, its associated configuration database, and a farm account on the local computer based on the specified connection string.

· Open method can be used to get a remote server farm based on the specified connection string.
· Servers property of SPFarm object is used to get the collection of all physical computers that are in the server farm. This property returns a SPServerCollection object which is a collection of SPServer objects (one SPServer object for each physical computer in the current server farm).

· Services property of SPFarm object is used to get the collection of all the services that are in the server farm. This property returns a SPServiceCollection object which is a collection of SPService objects (one SPService object for each Service in the current server farm).

· Solutions property of SPFarm object is used to get the collection of all the solutions that are in the server farm. This property returns a SPSolutionCollection object which is a collection of SPSolution objects (one SPSolution object for each Solution in the current server farm).

SPServer Object
SPServer object represents a physical computer in the server farm.
ServiceInstances property is used to get the collection of individual service instances that run on the individual computer.

SPService Object
SPService object represents a logical service or application installed in the server farm.
SPSolution Object
SPSolution object represents a SharePoint Solution installed in the server farm.
SPWebService Object
SPWebService object represents a Web service that contains one or more WSS web applications. It can be used to access configuration settings for a specific logical service or web application.

WebApplications property is used to get the collection of all the web applications that are running within this service. It returns SPWebApplicationCollection object which is a collection of SPWebApplication objects (one SPWebApplication object for each web application).

SPServiceInstance Object
SPServiceInstance object represents a single instance of service running in the server computer.ServiceInstances property of the SPServer object can be used to get the SPServiceInstanceCollection object that represents all the service instances that are currently running on a server computer.

Service property is used to get the SPService object that contains the farm-wide settings that apply to the service that this instance implements.

Server property is used to get the SPServer object on which this instance is installed.
SPDatabaseServiceInstance Object
SPDatabaseServiceInstance object represents a single instance of a database service running on the server computer. The SPDatabaseServiceInstance class derives from the SPServiceInstance class and thus inherits the Service property, which provides access to the service or application that the instance implements. TheDatabases property gets the collection of content databases used in the service.

SPWebApplication Object
SPWebApplication object represents a WSS web application and it contains a set of content databases and site collections. The SPWebApplication object provides access to credentials and other server farm wide application settings

SPWebApplication inherits from SPPersistedObject, which means that an object of the class persists in the configuration database.

SPWebApplication class enables administrators to access IIS properties without opening IIS Manager for example with the help of IisSettings and ApplicationPool property, we can access the properties of the IIS application pool to which the WSS Web application is assigned.

Sites property is used to get the collection of site collections within the Web application. It returns SPSiteCollection object which is a collection of SPSite objects.

ContentDatabases property is used to get the collection of content databases used in the Web application. It return SPContentDatabaseCollection object which is a collection of SPContentDatabase objects.

SPDatabase Object
SPDatabase object encapsulates access to Microsoft SQL Server databases. Databases property of theSPDatabaseServiceInstance object can be used to get the collection of databases that support the database service instance.

SPContentDatabase Object
SPContentDatabase object represents a content database that contains user data for a SharePoint web application. ContentDatabases property of the SPWebApplication object can be used to get the collection of all the content databases that are used by the Web application. ContentDatabase property of the SPSiteobject can also be used to get the content database for a site collection.

Sites property is used to get the collection of site collections for which the content database stores data.
WebApplication property is used to get the parent Web application.
SPSiteCollection Object
SPSiteCollection object represents the collection of site collections within the Web application and each site collection is represented by SPSite object.


Object model of Site Architecture:
Following diagram shows the Windows SharePoint Services site architecture in relation to the SharePoint objects and collections. All these objects and collections are available in the “Microsoft.SharePoint” namespace.

SPSite Object
SPSite object represents a collection of sites in a Web application, including a top-level Web site and all its sub sites. This collection of sites is known as “Site Collection”. Each site in the site collection, top-level site as well as all its sub sites is represented by a SPWeb object.

Although a SPSite object represents a collection of sites, the SPSite class is not a collection in the sense of a class that implements ICollection. A SPSiteCollection class implements the latter interface and it represents a collection of SPSite objects.

SPSite object can be instantiated by following methods:
· SPSite constructor can be used to instantiate a SPSite object for a specific site collection within a console application, or windows application, or on an ASP.NET page

SPSite objSPSite = new SPSite("Absolute_URL");
· Within an ASP.NET application, Site property of the SPContext class can be used to get the SPSite objectthat represents the current site collection

SPSite objSPSite = SPContext.Current.Site;
· Get SPSiteCollection object from the Sites property of the SPWebApplication class. This SPSiteCollection represents the collection of site collections in a SharePoint Web application, so just use an indexer to return a single site collection from the collection.

SPSiteCollection objSiteCollection = objWebApplication.Sites;
int index = 0;
SPSite objSite = objSiteCollection[index];
· RootWeb property of SPSite class returns its child top-level website. In turn, the SPWeb object that represents the top-level Web site has a Webs property that holds all its immediate child sub sites. The AllWebs property of SPSite returns all the sub sites and the top-level Web site.

SPWeb Object
Each SharePoint website is represented by SPWeb object whether it is a top level website or a sub site. SPWeb object has members that can be used to manage a site, including its template and theme, as well as to access files and folders on the site.

SPWeb object can be a child of another SPWeb object or of a SPSite object. If it is the child of a SPSite object, it is the top-level Web site in its site collection. A hierarchy of Web sites always has exactly one top-level Web site. This site is represented by a SPWeb object which is an immediate child of a SPSite object.

SPWeb object has a Webs property that returns a collection of other SPWeb objects; specifically, the immediate child sub sites under it.

The Lists property returns a SPListCollection object that represents all the lists in the site. Each list in a site is represented by SPList object.

SPWeb object can be instantiated by following methods:
· To get SPWeb object for top level website following code snippet can be used:
1) SPSite objSPSite = new SPSite("Absolute_URL");
SPWeb objSPWeb = objSPSite.OpenWeb();
OR
2) SPSite objSPSite = new SPSite("Absolute_URL");
SPWeb objSPWeb = objSPSite.RootWeb();
· To get SPWeb object for top level website as well as for each sub site, following code snippet can be used:
SPSite objSPSite = new SPSite("Absolute_URL");
SPWeb objSPWeb = objSPSite.AllWebs[index];
· To get SPWeb object for each sub site only, following code snippet can be used:
SPSite objSPSite = new SPSite("Absolute_URL");
SPWeb objSPWeb = objSPSite.OpenWeb();
SPWeb objSPWeb = objSPWeb.Webs[index];
SPList Object
Each shared list and document library in a SharePoint website is represented by SPList object. SPList object has members that are used to manage the list or access items in the list.

· GetItems method can be used to perform queries that return specific items.
· Fields property returns a SPFieldCollection object that represents all the fields, or columns, in the list.
· Items property returns a SPListItemCollection object that represents all the items, or rows, in the list.
· Folders property returns the collection of folder items for the list.
· Lists property can be used to get the parent collection of lists to which the list belongs.
· ParentWeb property can be used to get the parent Web site for the list.
· Delete method can be used to delete the list.
· GetChanges method can be used to get from the change log the collection of changes that have occurred in the list.
· Update method can be used to update the database with changes that are made to the list.
SPField Object
SPField object represents a field in a list.
· Title property can be used to get or set the display name for the field.
· Type property can be used to get or set the type of the field.
· Delete method can be used to delete the field.
· Update method can be used to update the database with changes that are made to the field.
SPListItem Object
SPListItem object represents a single row item in the list.
· Fields property returns the collection of all fields in the parent list of the SPListItem.
· Delete method can be used to delete a row from the list.
· Update method can be used to update a row in the list.
· Following code snippet can be used to add a row in the list:
spListItemObject = spListObject.Items.Add();
//assign values for each column of this row
spListItemObject.Update();



Thanks,
Rajesh Batchu,
Share Point Developer,
+1 23456 4 234 8


No comments:

Post a Comment