none
Required steps to add new Enterprise wiki pages inside my Event Receivers using server-side code RRS feed

  • Question

  • I am working on an enterprise wiki site collection inside sharepoint server 2013. now i created an event receiver which will get fired when an item inside a list is added. and the event receiver will be creating  2 wiki pages. now i tried the following steps, which will create 2 wiki pages and add links between them:-

     public override void ItemAdded(SPItemEventProperties properties)
            {
                base.ItemAdded(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);
    
                    ///First page - about.aspx
                    PublishingPageCollection pPages = pWeb.GetPublishingPages();
                    PublishingPage pPage1 = pPages.Add(properties.ListItem.Title + " - About.aspx", pageLayout);
                    SPListItem newpage1 = pPage1.ListItem;
                    newpage1["Title"] = properties.ListItem.Title+" - About.aspx";
                    newpage1["PublishingPageContent"] = "<a href='/sites/siteA/Pages/" + properties.ListItem.Title + " - Main.aspx" + @"'>Back To Main Page</a> ";
                              
                    ///Second Page  - Main.aspx              
                    PublishingPage pPage = pPages.Add(properties.ListItem.Title + " - Main.aspx", pageLayout);
                    SPListItem newpage = pPage.ListItem;
                    newpage["Title"] = properties.ListItem.Title + " - Main.aspx";//"Page added programmatically";
                    
                    newpage["PublishingPageContent"] = @"<table class='ms-rteTable-default' cellspacing='0' style='width: 65%; height: 803px; text-align: left;'>
                        <tbody>
          <tr class='ms-rteTableEvenRow-default'>
             <td class='ms-rteTableEvenCol-default' style='width: 599px;'>​​Solution &amp; Customer Overview</td>
             <td class='ms-rteTableOddCol-default' style='width: 64%;'>
                <div>
                   <a href='/kb/CustomerServiceKB/Pages/" + properties.ListItem.Title + " - About.aspx" + @"'>About customer</a> (Introduction)</div>
                ";
                    newpage.Update();
                    newpage1.Update();
                   
                   
                }
            }
    
    
        }

    now i test this an i got 2 wiki pages (main.aspx & about.aspx) and the links between them are working well.

    But i am not sure if i am doing things correctly inside my event receiver or i am missing some steps ? espically when i am linking the 2 wiki pages together using normal <a> html tags??


    • Edited by johnjohn11 Saturday, January 28, 2017 3:20 AM
    Saturday, January 28, 2017 3:13 AM

Answers

  • Hi John,

    Yes, we can set HTML code <a/> tag for the PublishingPageContent field to link other wiki pages.

    Best Regards,

    Dennis


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

    • Marked as answer by johnjohn11 Monday, February 6, 2017 1:55 PM
    Monday, February 6, 2017 2:58 AM
    Moderator

All replies

  • Hi,

    Any update?

    What do you mean about "espically when i am linking the 2 wiki pages together using normal <a> html tags?"?

    Your code seems works.

    Best Regards,

    Dennis


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


    Tuesday, January 31, 2017 7:50 AM
    Moderator
  • Hi,

    Any update?

    What do you mean about "espically when i am linking the 2 wiki pages together using normal <a> html tags?"?

    Your code seems works.

    Best Regards,

    Dennis


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


    i mean when creating new wiki pages inside my server-side event receiver, and i need to add hyper-links inside each wiki page which reference other wiki pages...  then is this done by adding a normal HTML <a> tag ?? or there are extra steps i need to do ?

    Thanks

    Friday, February 3, 2017 4:03 PM
  • Hi John,

    Yes, we can set HTML code <a/> tag for the PublishingPageContent field to link other wiki pages.

    Best Regards,

    Dennis


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

    • Marked as answer by johnjohn11 Monday, February 6, 2017 1:55 PM
    Monday, February 6, 2017 2:58 AM
    Moderator