SharePoint 2013 Server Object Model (SOM) Programming

SharePoint Server Object Model Programming allows you to write code and communicates with SharePoint objects if you are inside SharePoint context. It provides a set of classes which is executed at server side. Server Object Model Programming is same in SharePoint 2010 and SharePoint 2013. 

SharePoint 2013 Server Object Model Tutorial

In this blog, I will demonstrate SOM programming in SharePoint 2013 using Visual Studio 2015. You can use Server object model in a console application, windows form and other ASP.Net Applications. 
In SharePoint Server Object Model it is necessary to reference Microsoft.SharePoint dll in the working project. You can implement SOM model in a system only if SharePoint Server is installed.

You may find Microsoft.SharePoint dll in Windows Drive in my case it is C:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI

Below are list of classes used in SharePoint Server Object Model

  • SPFarm
  • SPWeb
  • SPSite
  • SPList
  • SPNavigationNode
  • SPUser
  • SPWebApplication

SharePoint Server Object Model Architecture

SharePoint Server Object Model

Let's See SharePoint 2013 Server Object Model Examples

Below code snippet will give you current Farm details.

               SPFarm objFarm = SPFarm.Local;
            long farmVersion = objFarm.Version;
            Guid farmID = objFarm.Id;
            SPObjectStatus farmStatus = objFarm.Status;
            Console.WriteLine("Farm Version is:" + farmVersion);
            Console.WriteLine("Farm ID is:" + farmID);
            Console.WriteLine("Farm Status is:" + farmStatus);

Below code snippet will create a site in your web application.

SPSite objSite = new SPSite("http://localhost:1000");
            SPWebApplication objWebApp = objSite.WebApplication;
            objWebApp.Sites.Add("/sites/demosite", "Demo Site", "This is a demosite", 1033, "STS#0", @"corp\administrator", "Administrator", "");

Below code snippet will add a link in top navigation and quick launch

SPSite objSite = new SPSite("http://localhost:1000");
            SPWeb objWeb = objSite.RootWeb.Webs[""];//leave it empty and run the code.
            SPNavigationNode objNode = new SPNavigationNode("SharePointCafe Blog", "", true);
            Console.WriteLine("Task Done");

Please visit my Youtube Channel for these SharePoint 2013 Server Side Object Model Demonstration.



What is Web API? When should we use in our projects?