Question

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 ?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top