0

I am working on an item added event receiver. the event receiver will fire when an item inside a generic list is added, and it is scoped at the web level. here is the elements.xml file:-

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListTemplateId="100">
      <Receiver>
        <Name>EventReceiver1ItemAdded</Name>
        <Type>ItemAdded</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>wikipages.EventReceiver1.EventReceiver1</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>
  </Receivers>
</Elements>

inside the event receiver i will be creating 3 wiki pages, as follow:-

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
                        PublishingPageCollection pPages = pWeb.GetPublishingPages();

PublishingPage pPage = pPages.Add(newPageName + ".aspx", pageLayout);
                            SPListItem newpage = pPage.ListItem;
                            newpage["Title"] = newPageName;//"Page added programmatically";
                            newpage["PublishingPageContent"] = r;
                            newpage["Standard"] = tempWikiPage.ListItemAllFields["Standard"];
                            newpage["Document_x0020_Type"] = tempWikiPage.ListItemAllFields["Document_x0020_Type"];
                            newpage["Departments"] = tempWikiPage.ListItemAllFields["Departments"];
                            newpage["Wiki_x0020_Page_x0020_Categories"] = currenttermset.Id.ToString();
                            newpage.Update();



                     ///second page


PublishingPage pPage2 = pPages.Add(newPageName + ".aspx", pageLayout);
                            SPListItem newpage2 = pPage2.ListItem;
                            newpage2["Title"] = newPageName;//"Page added programmatically";
                            newpage2["PublishingPageContent"] = r;
                            newpage2["Standard"] = tempWikiPage.ListItemAllFields["Standard"];
                            newpage2["Document_x0020_Type"] = tempWikiPage.ListItemAllFields["Document_x0020_Type"];
                            newpage2["Departments"] = tempWikiPage.ListItemAllFields["Departments"];
                            newpage2["Wiki_x0020_Page_x0020_Categories"] = currenttermset.Id.ToString();
                            newpage2.Update();

but i have noted that during the execution of my event receiver, and when the first newpage.Update(); is executed, an action from a list named "TaxonomyHiddenList" will be fired as follow:-

enter image description here

so can anyone advice what is this exactly ? and why this will fire for one time only ? and it is related to creating wiki pages inside my event receiver ?

1

One or more of the fields you set in the wiki page is likely a Managed Metadata Field. When you set it as such:

newpage["Wiki_x0020_Page_x0020_Categories"] = tempWikiPage.ListItemAllFields["Departments"];

you are likely setting the managed metadata field of that page to a taxonomy term from the term store which has not been used in that site collection previously. When that happens, SP automatically creates an entry in the TaxonomyHiddenList for that term, thus firing the item added event.

  • yes you are right .. so there is not anything to worry about ,, is this correct ? – john Gu Feb 3 '17 at 15:37
  • 1
    The event will fire more often than you need using more processing power, but otherwise I don't think there is anything else to worry about – Kevin Stone Feb 3 '17 at 15:57
  • and most importantly there is not any think i can do to stop this ? i mean if i am creating a wiki page inside my ER and i am assigning a new Term to the wiki page,, then my event receiver will fire ,, since my event receiver is configured to run on generic lists ,, which is the list type for the TaxonomyHiddenList also ? is this correct? – john Gu Feb 3 '17 at 16:06
  • Yep, the way to prevent this to me would be to install the event receiver only to certain specific lists. I am used to working with remote event receivers in provider hosted SP apps and that is how I would do it there – Kevin Stone Feb 3 '17 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.