using (SPSite site = new SPSite(siteUrl)) { // do some work with the site collection } // Dispose() is called automatically
SPSite site = new SPSite(siteUrl); try { // do some work with the site collection } finally { site.Dispose(); }This example follows the same pattern as Example 1, but uses a try-finally block instead of a using block to ensure proper disposal of the SPSite object. Package Library: Microsoft.SharePoint Both examples use the Microsoft.SharePoint namespace which is part of the Microsoft.SharePoint.dll assembly. This assembly is part of the SharePoint Server API and is used to interact with SharePoint sites and objects.