A client running SharePoint Server 2019 asked me last month why their nightly cleanup job could touch every site collection on the farm, while the same logic rewritten for SharePoint Online couldn’t even load. The answer is where the code runs: their job used the server-side object model, which only exists on the farm’s own servers.
In this tutorial, we’ll walk through the SharePoint server object model (SSOM): the SPSite, SPWeb, SPList and SPListItem hierarchy, a console app that reads and writes a Service Requests list, the Dispose rules that keep a farm healthy, elevated code, and how SSOM compares with CSOM, JSOM, REST and Microsoft Graph.
Quick answer: SSOM is the set of .NET classes in Microsoft.SharePoint.dll (namespace Microsoft.SharePoint) that run on a SharePoint Server farm server: 2016, 2019 or Subscription Edition. Open a site with using (SPSite site = new SPSite(url)) using (SPWeb web = site.OpenWeb()), get a list with web.Lists.TryGetList("Service Requests"), and query it with SPQuery. It doesn’t work in SharePoint Online; use CSOM, REST or Microsoft Graph there.
What is the SharePoint server object model?
The server object model is the biggest API SharePoint has. Microsoft puts most of its classes in the Microsoft.SharePoint namespace, and the farm-level classes in Microsoft.SharePoint.Administration. The assemblies sit in the global assembly cache of every server.
Your own server-side code is deployed to the farm as a farm solution. If you’re still deciding between on-premises and cloud, I compare them in SharePoint Online vs. SharePoint on-premises.
Because it runs in-process, it powers timer jobs, custom PowerShell cmdlets and Central Administration pages. The flip side: it needs a SharePoint server to run on.
Important: SSOM is on-premises only. Microsoft doesn’t let anyone run custom code on SharePoint Online servers, so “SSOM online” isn’t a thing. For Microsoft 365 you use the client-side options covered later.
What type of model does SharePoint use? The SSOM object hierarchy
SharePoint uses a hierarchical object model: every object lives inside a parent, from the farm down to a single list item. Once you know the chain, most SSOM code is just walking it with the right class.

| SharePoint component | SSOM class | Namespace |
|---|---|---|
| Farm | SPFarm | Microsoft.SharePoint.Administration |
| Server | SPServer | Microsoft.SharePoint.Administration |
| Web application | SPWebApplication | Microsoft.SharePoint.Administration |
| Content database | SPContentDatabase | Microsoft.SharePoint.Administration |
| Site collection | SPSite | Microsoft.SharePoint |
| Site (web) | SPWeb | Microsoft.SharePoint |
| List or library | SPList / SPDocumentLibrary | Microsoft.SharePoint |
| Column | SPField | Microsoft.SharePoint |
| List item | SPListItem | Microsoft.SharePoint |
| Query | SPQuery | Microsoft.SharePoint |
Two naming traps catch beginners. SPSite is a site collection, not a site, and SPWeb is the site. And the item class you’ll use every day is SPListItem; older posts (including the first version of this one) listed SPItem, which is only its abstract base class.
Set up the console project on the farm server
SSOM code has to run on a server that’s joined to the farm, under an account that can reach the content database (the farm account, or one you’ve granted access with Add-SPShellAdmin, which I list in the SharePoint PowerShell commands cheat sheet). From a developer laptop, new SPSite() fails because there’s no local farm to connect to.
- Create a Console App (.NET Framework) project in Visual Studio, not a .NET 8 or later console app. SSOM needs the full .NET Framework that the farm runs (4.7.2 or 4.8).
- Set the platform target to x64 and clear Prefer 32-bit. SharePoint is 64-bit only, so a 32-bit process can’t load it.
- Add a reference to
Microsoft.SharePoint.dllfromC:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI. SharePoint Server 2016, 2019 and Subscription Edition all use the 16 folder. - Add
using Microsoft.SharePoint;at the top of Program.cs.

If you prefer editing the project file directly, these are the lines that matter in the .csproj:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<PlatformTarget>x64</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.SharePoint">
<HintPath>C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.dll</HintPath>
</Reference>
</ItemGroup>
Now the smallest useful program. It opens our SPGuides site collection, prints the site title and lists every visible list with its item count:
using System;
using Microsoft.SharePoint;
class Program
{
static void Main()
{
using (SPSite site = new SPSite("http://spguides-sp2019/sites/SPGuides"))
using (SPWeb web = site.OpenWeb())
{
Console.WriteLine("Site: " + web.Title);
foreach (SPList list in web.Lists)
{
if (!list.Hidden)
Console.WriteLine(list.Title + " - " + list.ItemCount + " items");
}
}
}
}
Run on the farm server, it should print the SPGuides site title followed by one line per list, such as Service Requests with its current item count. Notice the two using statements: both objects are disposed the moment the block ends, which matters more than anything else on this page.
Read list items with SPList and SPQuery
Same SPGuides site, now with the Service Requests list. Looping over list.Items loads every item and every column, so on a real list I always use SPQuery with a CAML filter. If CAML is new to you, the CAML query builder guide shows how to build and test the XML.
using (SPSite site = new SPSite("http://spguides-sp2019/sites/SPGuides"))
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists.TryGetList("Service Requests");
if (list == null) { Console.WriteLine("List not found."); return; }
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='Status'/><Value Type='Choice'>Open</Value></Eq></Where>"
+ "<OrderBy><FieldRef Name='Created' Ascending='FALSE'/></OrderBy>";
query.ViewFields = "<FieldRef Name='Title'/><FieldRef Name='Status'/><FieldRef Name='Priority'/>";
query.ViewFieldsOnly = true;
query.RowLimit = 100;
SPListItemCollection items = list.GetItems(query);
foreach (SPListItem item in items)
{
Console.WriteLine(item.ID + " " + item.Title + " " + item["Priority"]);
}
}
This returns only items whose Status is Open, newest first, with just three columns loaded. ViewFieldsOnly keeps SharePoint from pulling the rest, and RowLimit caps one page at 100 items. TryGetList returns null instead of throwing when the list name is wrong, which is why I check it first.
Add and update list items with SPListItem
Writing is just as direct. AddItem() gives you a new SPListItem, you set fields by internal name, and nothing reaches the database until you call Update():
using (SPSite site = new SPSite("http://spguides-sp2019/sites/SPGuides"))
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Service Requests"];
// Add a new item
SPListItem newItem = list.AddItem();
newItem["Title"] = "Printer offline in the Denver office";
newItem["Status"] = "Open";
newItem["Priority"] = "High";
newItem.Update();
// Update an existing item by ID
SPListItem existing = list.GetItemById(42);
existing["Status"] = "In Progress";
existing.Update();
}
After it runs, the list should show a new High priority request titled “Printer offline in the Denver office”, and item 42 should move to In Progress. Choice columns take the choice text; person and lookup columns need SPFieldUserValue or SPFieldLookupValue objects instead of plain strings.
Pro Tip: use SystemUpdate(false) instead of Update() when a background job shouldn’t change Modified, Modified By or the version number.
Query large lists without hitting the threshold
On lists past the list view threshold (5,000 items by default on SharePoint Server), an unindexed filter can be blocked. Index the column you filter on, then page through results with ListItemCollectionPosition. Microsoft’s large-list guidance suggests pages of 2,000 items or fewer:
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='Status'/><Value Type='Choice'>Closed</Value></Eq></Where>";
query.RowLimit = 2000;
do
{
SPListItemCollection page = list.GetItems(query);
foreach (SPListItem item in page)
{
// process the item
}
query.ListItemCollectionPosition = page.ListItemCollectionPosition;
}
while (query.ListItemCollectionPosition != null);
The loop ends when SharePoint returns no position for the next page, so every Closed item gets processed in chunks instead of one huge request.
Dispose rules: when to use using blocks
SPSite and SPWeb hold unmanaged resources and a lot of memory. Leak them in a loop and the server’s memory climbs until the application pool recycles. The rules Microsoft documents are short:
| How you got the object | Dispose it? |
|---|---|
| new SPSite(url) or new SPSite(guid) | Yes, with using |
| site.OpenWeb(…), site.AllWebs[…], AllWebs.Add(…) | Yes, with using |
| SPContext.Current.Site / SPContext.Current.Web | No, SharePoint disposes it |
| SPContext.Current.Site.RootWeb | No |
| SPList, SPListItem, SPField | No, they aren’t disposable |
Two more habits: never keep an SPSite or SPWeb in a static variable (store the URL or GUID instead), and don’t create an SPSite only to reach its parent. SPWebApplication.Lookup(new Uri(url)) gets the web application without opening a site collection.
SPContext in web parts and application pages
Inside a farm-solution web part or application page, the request already knows its site, so you read it from SPContext. In a console app SPContext.Current is null, because there’s no web request.
// Inside a farm-solution web part or application page
SPWeb web = SPContext.Current.Web; // do NOT wrap this in using or call Dispose()
SPList list = web.Lists.TryGetList("Service Requests");
// A different site opened from the context: you own it, so dispose it
using (SPWeb hr = SPContext.Current.Site.OpenWeb("HR"))
{
// work with the HR site
}
Wrapping SPContext.Current.Web in a using block is the most common SSOM bug I find in old code. It disposes an object SharePoint still needs, and the page fails in odd ways later. For new UI on modern pages, though, I’d build an SPFx client-side web part instead of a farm solution.
RunWithElevatedPrivileges and AllowUnsafeUpdates
Sometimes a web part must write where the signed-in user has no rights, like an audit log. SPSecurity.RunWithElevatedPrivileges runs a delegate as the system account, but only objects created inside the delegate get those rights, so open a new SPSite from the IDs:
Guid siteId = SPContext.Current.Site.ID;
Guid webId = SPContext.Current.Web.ID;
SPUtility.ValidateFormDigest(); // writes follow, so validate first (Microsoft.SharePoint.Utilities)
SPSecurity.RunWithElevatedPrivileges(delegate ()
{
using (SPSite site = new SPSite(siteId)) // a NEW SPSite inside the delegate
using (SPWeb web = site.OpenWeb(webId))
{
SPList log = web.Lists["Request Audit Log"];
SPListItem entry = log.AddItem();
entry["Title"] = "Request 42 reassigned to Jessica Moore";
entry.Update();
}
});
Microsoft says to call SPUtility.ValidateFormDigest() or SPWeb.ValidateFormDigest() before an elevated block that writes. Keep elevated blocks tiny, and never let user input decide what runs inside them.
AllowUnsafeUpdates is a different switch: it lets code change data on a GET request or without security validation. Microsoft’s advice is to do writes on POST instead, and if you truly must set it, reset it in a finally block. In a console app there’s no web request, so you normally leave it alone.
web.AllowUnsafeUpdates = true;
try
{
item["Status"] = "Closed";
item.Update();
}
finally
{
web.AllowUnsafeUpdates = false;
}
SSOM vs CSOM vs JSOM vs REST vs Microsoft Graph
| API | Where the code runs | SharePoint Server | SharePoint Online | Typical use |
|---|---|---|---|---|
| SSOM (Microsoft.SharePoint) | On a farm server | Yes | No | Timer jobs, farm solutions, admin tools |
| CSOM (.NET client OM) | Any machine, batched calls | Yes | Yes | Remote C# tools, migrations, PnP |
| JSOM (JavaScript OM) | Browser, async batches | Yes | Yes (legacy) | Older page scripts |
| REST (_api) | Anything that speaks HTTP | Yes | Yes | SPFx, Power Automate, scripts |
| Microsoft Graph | Any app, Entra ID auth | No | Yes | Cross-Microsoft 365 apps |
When to use which: pick SSOM for farm-scoped work on SharePoint Server, like a nightly timer job. For remote C# code, the same SPSite/SPWeb ideas map to Site and Web in the SharePoint CSOM tutorial.
Old page scripts use the JavaScript object model (JSOM), while anything new speaks the SharePoint REST API or Microsoft Graph.
For new Microsoft 365 work, Microsoft now recommends Graph first and SharePoint REST or CSOM for what Graph doesn’t cover. If you’re moving a farm to Subscription Edition first, my SharePoint Server Subscription Edition guide covers the requirements.
Common errors and how to fix them
- FileNotFoundException: “The Web application at … could not be found”: the URL doesn’t match an alternate access mapping, the code isn’t running on a farm server, or the project is 32-bit. Use the exact AAM URL and target x64.
- Access denied or the content database can’t be opened: the account running the app has no database access. Run it as the farm account or grant access with Add-SPShellAdmin.
- “Updates are currently disallowed on GET requests”: the write runs on a GET without validation. Move it to a POST handler, or set AllowUnsafeUpdates and reset it in finally.
- Memory climbs and the app pool recycles: SPSite or SPWeb objects aren’t disposed. Add using blocks around every object you create.
- “The attempted operation is prohibited because it exceeds the list view threshold”: index the filtered column and page with RowLimit plus ListItemCollectionPosition.
If you’re porting the same logic to SharePoint Online, the client equivalents have their own traps, such as the collection has not been initialized error in CSOM.
If you work across on-premises and Microsoft 365, these guides pick up where this one stops:
Frequently Asked Questions
What is SSOM in SharePoint?
SSOM is the SharePoint server-side object model: the .NET classes in Microsoft.SharePoint.dll, such as SPSite, SPWeb, SPList and SPListItem, that run on a SharePoint Server farm server and work directly with sites, lists and farm settings.
Can I use the server object model in SharePoint Online?
No. Custom code can’t run on SharePoint Online servers, so SSOM is limited to SharePoint Server 2016, 2019 and Subscription Edition. In SharePoint Online use CSOM, the REST API, PnP or Microsoft Graph.
What is the difference between SPSite and SPWeb?
SPSite represents a site collection and SPWeb represents a single site inside it. You open an SPWeb from an SPSite with OpenWeb() or AllWebs[], and you dispose both when your code created them.
What type of model does SharePoint use?
SharePoint uses a hierarchical object model: farm, web application, site collection (SPSite), site (SPWeb), list (SPList) and list item (SPListItem). The server and client object models both follow that hierarchy.
Should I choose SSOM, CSOM or REST for a new project?
Use SSOM only for code that must run on the farm, such as timer jobs. For everything else use CSOM, REST or Microsoft Graph. Microsoft compares the API sets in Choose the right API set in SharePoint.

Hey! I’m Bijay Kumar, founder of SPGuides.com and a Microsoft Business Applications MVP (Power Automate, Power Apps). I launched this site in 2020 because I truly enjoy working with SharePoint, Power Platform, and SharePoint Framework (SPFx), and wanted to share that passion through step-by-step tutorials, guides, and training videos. My mission is to help you learn these technologies so you can utilize SharePoint, enhance productivity, and potentially build business solutions along the way.
Thank you, Kumar for your great help.