Search code examples
sharepointsharepoint-2010

GetCurrentPublishing page with SharePoint API


Is there anyway to get current publishing page with SharePoint API.


Solution

  • You can use code like the following to do this. Depending on the context of where you're calling it, you can be more or less defensive accordingly.

        var li = SPContext.Current.Item as SPListItem;
        if (li != null && PublishingPage.IsPublishingPage(li))
        {
            var pp = PublishingPage.GetPublishingPage(li);
        }