SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can i set an taxonomyfield during an itemAdding event?

i've got a TaxonomyFieldValue created from my propertybag.

public override void ItemAdding(SPItemEventProperties properties)
     //Get site and list we are working on
     SPSite CurrentSite = properties.OpenSite();
     using (SPWeb web = properties.OpenWeb())
         TaxonomySession taxonomySession = new TaxonomySession(CurrentSite);
         TaxonomyFieldValue taxvalue= new TaxonomyFieldValue(probertybagValue.ToString());
         properties.AfterProperties["MyField"] = taxvalue.ToString();

Normaly i would use Taxonomy SetFieldValue option, but this can only use with an SPItem object, and we haven't that object during itemAdding

share|improve this question

i havent done this myself but why dont you implement the taxonomy:

    private void SetTaxononmyField(SPListItem newItem, TaxonomyFieldValue value, string fieldname)
        TaxonomyField field = newItem.Fields.GetFieldByInternalName(fieldname) as TaxonomyField;
        if (field != null)
            field.SetFieldValue(newItem, value);//Throws "Specified method is not supported" exception here

TaxonomyField.SetFieldValue throws "Specified method is not supported" Exception

hope it helps :)

share|improve this answer
The reason why i didn't implement that is that there is no SPListItem object in the ItemAdding Event. – Active_t Jan 21 '13 at 10:14
? but you can! using (SPWeb web = properties.Web) { SPList list = web.Lists["ListName"]; SPListItemCollection listItemCollection = list.Items; foreach (SPListItem listItem in listItemCollection) { }} from that you call the mthod that i stated ;) – ali Sharepoint Jan 21 '13 at 10:46

I had exactly the same requirement. What I did was use the ItemAdded event and set it to run Synchronous.

Hope this helps, Thanks

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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