Checking out an item in SharePoint provides the user with an exclusive lock to prevent the editing of that item. This prevents multiple users from making modifications at the same time. In this recipe, we will check out the publishing page we created in the Creating a publishing web part page recipe.
Checking out an item in a SharePoint list or library flags it with a checked out status. This prevents other users from modifying the item. A user with a manage lists or higher role may override the check out.
SharePoint list and library items may also be checked out with PowerShell or code using the server-side object model. There are a number of ways we could get the item to check out. In our example, we are using a CAML query to get the publishing page from the publishing site by its title. CAML is an XML-based markup language used to query SharePoint content.
Follow these steps to check out a publishing content using PowerShell:
Get-SPWeb
Cmdlet as follows:$web = Get-SPWeb "http://sharepoint/publishing"
$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$camlQuery = "<Where><Eq><FieldRef Name='Title'></FieldRef><Value Type='Text'>PowerShell Page</Value></Eq></Where>" $page = $pubWeb.GetPublishingPages($camlQuery)
$page.ListItem.File.CheckOut()
Dispose
method to discard the SPWeb
object as follows:$web.Dispose()
Follow these steps to check out a publishing content with code using the server-side object model:
using
statement as follows:using (var site = new SPSite("http://sharepoint/publishing"))
using
statement as follows:using (var web = site.OpenWeb())
var pubWeb = PublishingWeb.GetPublishingWeb(web);
var camlQuery = "<Where><Eq><FieldRef Name='Title'></FieldRef><Value Type='Text'>Code Page</Value></Eq></Where>"; var page = pubWeb.GetPublishingPages(camlQuery).First();
page.ListItem.File.CheckOut();
18.188.211.106