How I can find a specific publishing page inside PublishingPageCollection and get its HTML source RRS feed

  • Question

  • I am working on an event receiver inside my Enterprise wiki site collection inside SharePoint 2013. Now inside my event receiver I am trying to do the following:-

    1.  Find specific wiki page (by title, Name or UL).

    2.  For this page get its HTML Source code. Similar to the HTML source code I get when I edit a wiki page, click on “Edit Source” button.

    Now I have the following code inside my event receiver, where I am able to get all the wiki pages, but seems trying to get a wiki page by title or by name is not working using the indexer,, as the (PublishingPage pp) variable will always be null..

    public override void ItemAdded(SPItemEventProperties properties)
                SPWeb spCurrentSite = properties.OpenWeb();
                if (properties.List.Title.ToLower() == "customers")
                    PublishingSite pSite = new PublishingSite(properties.Site);
                    SPContentType ctype = pSite.ContentTypes["Enterprise Wiki Page"];
                    PageLayoutCollection pageLayouts = pSite.GetPageLayouts(ctype, true);
                    PageLayout pageLayout = pageLayouts["EnterpriseWiki.aspx"];
                    PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(properties.Web);
                    PublishingPageCollection pPages = pWeb.GetPublishingPages();
                    int t = pPages.Count;
                    PublishingPage pp = pPages["Test - Main"];// I have a wiki page with title= “Test – Main”

    so can anyone adivce if there is a way to get a specific wiki page by title,name or url and for this wiki page to get its HTML source?


    Monday, January 30, 2017 1:39 PM


  • Hi,

    We can use the following line of code to get the wiki page by title.

    PublishingPage page = pPages.Where(p => p.Title.Equals("Test - Main")).FirstOrDefault();

    Then get page content using this:

    var content=page.ListItem["PublishingPageContent"];

    Best Regards,


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact

    • Edited by Dennis GuoModerator Tuesday, January 31, 2017 7:43 AM
    • Marked as answer by johnjohn11 Tuesday, January 31, 2017 1:43 PM
    • Unmarked as answer by johnjohn11 Friday, February 3, 2017 4:03 PM
    • Marked as answer by johnjohn11 Friday, February 3, 2017 4:03 PM
    Tuesday, January 31, 2017 7:37 AM