Identify the Publishing site in SharePoint using PnP Core Component

This post contains the code-snippet returns the current web is Publishing or not

PnP core component contains the extension methods which help to achieve the SharePoint task in simple lines of code. So to know more about PnP Core component, have a look at “Introduction to PnP Core Component”.

WebExtensions.IsPublishingWeb (PnP Core Component) – This extension method checks the current web is activated with Publishing feature and returns the boolean value.

Supports: SharePoint 2013+, SharePoint Online

Assembly: OfficeDevPnP.Core.dll
Namespace: Microsoft.SharePoint.Client

Method:

bool IsPublishingWeb()

Returns boolean value

Syntax:
Single Line Code: Web.IsPublishingWeb()

Code Snippet:

The following example returns the child site’s server relative url..

[code lang=”csharp”]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core;

namespace PnPSitesCore.Samples
{
class Program
{
static void Main(string[] args)
{
string siteUrl = "https://sharepointonline.sharepoint.com";

AuthenticationManager authManager = new AuthenticationManager();

//Interactive Login to SharePoint site – Opens a Online signin page to authenticate the user
var context = authManager.GetWebLoginClientContext(siteUrl);
//Determines whether the Publishing feature is activated in current website
bool isPublishingWeb = context.Web.IsPublishingWeb();
Console.WriteLine(isPublishingWeb);

Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
}
[/code]

The above code also available from GitHub.

Shantha Kumar
Shantha Kumar
Articles: 280