My new blog present here.

Featured Post

Insights into Sitecore Search: A Definitive Introduction

A key component of digital experience management is effective information retrieval. A simplified approach is required for websites, applications, and platforms containing a lot of material so that consumers can easily get the data they require. This need is met by Sitecore, a well-known name in the field of digital experience platforms (DXPs), which provides powerful and comprehensive search functionality. We will travel into the realm of Sitecore Search in this article, learning about its capabilities, architecture , and the enormous value it offers both developers and end users. Introduction to Sitecore Search    A headless content discovery platform powered by AI , Sitecore Search enables you to build predictive and custom search experiences across various content sources. To extract and ...

How to get Publishing Page Meta Data (Column Value) in Sharepoint

Requirement:

The requirement is to identify status (Draft/Approved/Checkout/Pending/Published) of page in Pages library and also fetch the metadata of page using SharePoint Ojbect Model in Publishing Web.

Resolution:

With the help of PublishingWeb class (Microsoft.SharePoint.Publishing), we can access different components of Published Web site like Pages document library, Published site navigation bar and etc.

The PublishingWeb class provides publishing behavior for an SPWeb instance that supports publishing. This class cannot be inherited.

Namespace: Microsoft.SharePoint.Publishing
Assembly: Microsoft.SharePoint.Publishing (in microsoft.sharepoint.publishing.dll)


In this example we will identify status (Draft/Approved/Checkout/Pending/Published) of page and access metadata of Pages from Pages Library in Publishing Web:



using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using System.Web;
using Microsoft.SharePoint.Navigation;
using Microsoft.SharePoint.Publishing;


namespace GetPublishedData
{
class Program
{
static void Main(string[] args)
{
try
{

using (SPSite site = new SPSite("http://amitkumarmca04.blogspot.com"))
{
using (SPWeb web = site.OpenWeb())
{
// Check web is PublishingWeb or not
if (PublishingWeb.IsPublishingWeb(web))
{
// Get the PublishingWeb
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
// Get the Page list from PublishingWeb
SPList pagesList = publishingWeb.PagesList;
if (pagesList != null && pagesList.Items.Count > 0)
{
// Get a reference to a publishing page

foreach (SPListItem page in pagesList.Items)
{
//Find status (Draft/Approved/Checkout/Pending/Published) of page
if (page.ModerationInformation.Status == SPModerationStatusType.Draft)
{
Console.WriteLine("Page in Draft mode.");
}
else if (page.ModerationInformation.Status == SPModerationStatusType.Approved)
{
Console.WriteLine("Page in Approved mode.");
}
else if (page.ModerationInformation.Status == SPModerationStatusType.Pending)
{
Console.WriteLine("Page in Pendig mode.");
}

if (page.Level == SPFileLevel.Checkout)
{
Console.WriteLine("Page in Checkout mode.");
}
else if (page.Level == SPFileLevel.Published)
{
Console.WriteLine("Page in Published mode.");
}
else if (page.Level == SPFileLevel.Draft)
{
Console.WriteLine("Page in Draft mode.");
}

//Find metadata of page
if (string.Equals(page.Name, "AmitKumar.aspx", StringComparison.InvariantCultureIgnoreCase))
{
//Access the page metadata
Console.WriteLine(Convert.ToString(page["Title"]));
}
}
}
}
else
{
// If the SPWeb is not a PublishingWeb,
// then GetPagesListName returns the URL
// that would be used by the Pages list
// if the Publishing feature were to be
// activated.
string pagesListName = PublishingWeb.GetPagesListName(web);
//After getting the url we can access Pages list
}
}
}

}
catch (Exception ex)
{
throw;
}

}
}
}

Comments

micalaston said…
hey dude this is really nice blog and its very useful to learn metatag in sharepoint and also useful coding.please continue posted this type of another blog and thanks for sharing information
SaMolPP said…
hi,
can you pls tell, how to get teh controls within this page?
i would like to change the summarylink field within this page and change its url.
thnx ina dvance

Popular posts from this blog

Sitecore GraphQL Queries

Sitecore Experience Manager Cloud (XM Cloud) Building blocks

Configuring Sitecore Next.js Headless SXA Multisite App in a Sitecore Container