Approving a published item in SharePoint makes it available to be viewed by users who have read access but do not have contribute access to the item. In this recipe, we will approve the publishing page we created in the Creating a publishing web part page recipe.
Follow these steps to approve a publishing page:
When content approval is required, approving a published item makes it available for the users with read access to view the item.
SharePoint list and library items may also be approved with PowerShell or code using the server-side object model.
Follow these steps to approve a publishing page 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.Approve("My Notes")
Dispose
method to discard the SPWeb
object as follows:$web.Dispose()
Follow these steps to approve a publishing page with code using the server-side object model:
using
statement as follows:using (var site = new SPSite("http://sharepoint/publishing"))
using
statement: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.Approve("My Notes");
3.139.86.18