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

I'm trying to set the metadata value for a folder in a document library with the following code:

using (SPSite siteCollection = new SPSite("http://dev.site.com"))
        {
            using (SPWeb web = siteCollection.OpenWeb())
            {
                SPList customDocumentLibrary = web.Lists["Program Documents"];
                MetadataDefaults columnDefaults = new MetadataDefaults(customDocumentLibrary);

                SPFolder testFolder = customDocumentLibrary.RootFolder.SubFolders["Programs"];

                columnDefaults.SetFieldDefault("/Program Documents/Programs/Academics", "Programs", "Academics");
                columnDefaults.Update();
            }

        }

I'm getting the following error:

The given value for a taxonomy field was not formatted in the required <int>;#<label>|<guid> format. 

Does anyone have an example of how to pass in the parameters for SetFieldDefault()? I'm unsure what the int;#label is referring to in the error message (though I have the guid of the taxonomy field).

share|improve this question

2 Answers 2

up vote 5 down vote accepted

So it turns out the value you need to pass in for the taxonomy value is the following:

lcid;#Term Name|Guid of term

e.g.:

1033;#Academics|bc943091-79ac-4f5f-a79b-205e8e717823

The full code to set the metadata column default is here:

        using (SPSite siteCollection = new SPSite("http://www.yoursite.com"))
        {
            using (SPWeb web = siteCollection.OpenWeb("/yourweb/"))
            {

                SPList customDocumentLibrary = web.Lists["Documents"];
                SPFolder rootFolder = customDocumentLibrary.RootFolder;

                MetadataDefaults columnDefaults = new MetadataDefaults(customDocumentLibrary);

                columnDefaults.RemoveAllDefaults();
                columnDefaults.SetFieldDefault(rootFolder, "Programs", "1033;#Academics|bc943091-79ac-4f5f-a79b-205e8e717823");
                columnDefaults.Update();
            }

        }
share|improve this answer

Although it might work fine to provide the LCID as to the default value, it's not what you're supposed to supply. You should supply the ID of the listitem in the hidden list "/Lists/TaxonomyHiddenList" that corresponds to the term you're setting as default. This list is some sort of cache of all the terms you use inside your site, which is explained in more detail over here: http://www.wictorwilen.se/Post/Dissecting-the-SharePoint-2010-Taxonomy-fields.aspx

Hope this helps!

share|improve this answer

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.