Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Can somebody tell me, how to add default data for taxonomy fields in xml... currently i am doing this is a basic way, but not working...

  <Data>
  <Rows>
    <Row>
      <Field Name="TaxonomyField">DefaultValue</Field> // this is taxonomy field
      <Field Name="HtmlField">
        <![CDATA[ ​<div><strong>Hi,</strong></div>
                  <div>Sample data</div>
        ]]>
      </Field>
    </Row>
  </Rows>
</Data>
share|improve this question
add comment

3 Answers

Add your term in the form "{WssId};#{TermLabel}|{TermId}" where WssId is the ID of the list item in the hidden taxonomy list that represents the term you are interested in.

For example:

<Field Name="TaxonomyField">1;#Cake|{5D43EEC1-A777-4BD1-B4FB-F04730674369}</Field>

If you don't know what the WssId will be then use -1 and SharePoint will figure it out for you.

<Field Name="TaxonomyField">-1;#Death|{548BF984-104D-4B8D-9073-DA87A2BB864D}</Field>
share|improve this answer
add comment

I don't doubt @Per Jacobsen's answer. Nevertheless, you should try creating a sample list with some taxonomyfield values filled out.

Then, choose to save that list out as a list template (.stp file). Be sure to check the box to preserve existing data.

Download the .stp file to your PC, change the extension to .cab. Use a program like IZarc to open and explore the contents of the .cab file.

Within that, you should be able to find a data/xml file that shows how SharePoint prefers to save out the ROW data. Maybe it skips it, but, maybe the mystery is solved within.

I've used this technique in the past to port the ROW data over into my Visual Studio list-instance features, where I wanted the feature to create a list pre-filled with data.

share|improve this answer
add comment

I don't think it's possible because behind the scene a TaxonomyField is a lookup field into a HiddenList where the DefaultValue item has to be added and then you have to reference the ID of that.

So instead you should add your default data in the FeatureActivated method of a FeatureReciver. This is in fact a good thing because using <Data><Rows><Row> will create a lot of duplicates if you activate/deactivate your Feature multiple times, but when you add the row using code you can check and only do it if the list is empty.

See Walkthrough: Add Feature Event Receivers and Programmatically Setting Taxonomy Field Values

share|improve this answer
add comment

Your Answer

 
discard

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.