I am working on an event receiver inside sharepoint server 2013. the event receiver will fire when a user added a new item inside a custom list. Now i am trying to do the following :-
1- get the current item title using properties.ListItem.Title;
2- search the term store based on the item title.
3- create a new wiki page, add for the wiki category column to assign it the term i retrieved on step-2.
now i have the following code:-
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
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();
PublishingPage pPage = pPages.Add(newPageName+".aspx", pageLayout);
newpage["Wiki_x0020_Page_x0020_Categories"] = properties.ListItem.Title.Trim();
now i was not expecting my above code to work, as i am trying to assign a string to a managed property column. so i got this error:-
The given guid does not exist in the term store
so can anyone advice how i can search the term store and get the related term which is equal to the properties.ListItem.Title
and then assign the term to the newpage["Wiki_x0020_Page_x0020_Categories"]
column ?
Wiki_x0020_Page_x0020_Categories
is taxonomy column and you want to set its value toproperties.ListItem.Title
. Correct ? Also,properties.ListItem.Title
value (term) will be present in term store, is that correct ?