Checking out publishing content for editing

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.

How to do it...

Follow these steps to check out a publishing page:

  1. Navigate to the SharePoint list or library that contains the item to be checked out in your preferred web browser.

    Tip

    In our example, we will be using the Pages library and the publishing page we created in the Creating a publishing web part page recipe.

  2. Select the item by clicking on the checkmark on the item.
  3. Select Check Out from the FILES tab in the ribbon as shown in the following screenshot:
    How to do it...

How it works...

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.

There's more...

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.

Checking out publishing content using PowerShell

Follow these steps to check out a publishing content using PowerShell:

  1. Get the site using the Get-SPWeb Cmdlet as follows:
    $web = Get-SPWeb "http://sharepoint/publishing"
    
  2. Get the publishing site from the SharePoint site as follows:
    $pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
    
  3. Get the publishing page using the following CAML query:
    $camlQuery = "<Where><Eq><FieldRef Name='Title'></FieldRef><Value Type='Text'>PowerShell Page</Value></Eq></Where>"
    
    $page = $pubWeb.GetPublishingPages($camlQuery)
    
  4. Check out the publishing page using the following command:
    $page.ListItem.File.CheckOut()
    
  5. Use the Dispose method to discard the SPWeb object as follows:
    $web.Dispose()
    

Checking out publishing content with code using the server-side object model

Follow these steps to check out a publishing content with code using the server-side object model:

  1. Open the site collection containing the site in a using statement as follows:
    using (var site = new SPSite("http://sharepoint/publishing"))
  2. Open the site in a using statement as follows:
    using (var web = site.OpenWeb())
  3. Get the publishing site from the SharePoint site.
    var pubWeb = PublishingWeb.GetPublishingWeb(web);
  4. Get the publishing page with the following CAML query:
    var camlQuery = "<Where><Eq><FieldRef Name='Title'></FieldRef><Value Type='Text'>Code Page</Value></Eq></Where>";
    
    var page = pubWeb.GetPublishingPages(camlQuery).First();
  5. Check out the publishing page as follows:
    page.ListItem.File.CheckOut();

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.211.106