I am using sharepoint 2010. I have a document library which is using some custom content type. This content type has 2 custom fields which are termstore fields.
These are the names of the fields:
Subcategorie
Categorie
I would like to get the parent of the selected term in the field "Subcategorie" and set it to the field "Categorie".
This is the code:
public override void ItemUpdated(SPItemEventProperties properties)
{
// SPWeb web = properties.Web;
SPList list = properties.List;
SPListItem listItem = properties.ListItem;
SPSite CurrentSite = properties.OpenSite();
using (SPWeb web = properties.OpenWeb())
{
// check if this is a document library
if (list.BaseType == SPBaseType.DocumentLibrary)
{
var beforeItemSubCategorie = properties.BeforeProperties["Subcategorie"];
var afterItemSubCategorie = properties.AfterProperties["Subcategorie"];
var beforeItemCategorie = properties.BeforeProperties["Categorie"];
var afterItemCategorie = properties.AfterProperties["Categorie"];
string subCategorieInternalName = web.Lists[properties.ListId].Fields["Subcategorie"].InternalName;
string categorieInternalName = web.Lists[properties.ListId].Fields["Categorie"].InternalName;
properties.ListItem[categorieInternalName] = // get the parent of the term from the field "subcategorie". But how???
EventFiringEnabled = false;
properties.ListItem.SystemUpdate();
EventFiringEnabled = true;
}
}
base.ItemUpdated(properties);
}