Second Life of a Hungarian SharePoint Geek

March 3, 2010

Validation messages for the TaxonomyWebTaggingControl

Filed under: Reflection, SP 2010, Taxonomies — Tags: , , — Peter Holpar @ 03:41

When working with the TaxonomyWebTaggingControl it is important to be able to identify the source of a validation issue. In this task Reflector helps a lot but useful to know which specific error constant belongs to the validation message you see on the user interface.

The validation process call chain in this control is as follows:

Validate —-> ResolveUnboundTerm ––> AddNewKeyword
             \—>   ResolveBoundTerm —> AddNewTerm

The methods contain the following error message references (see Resources.GetString calls in the methods):

 

Validate

TermNotValid
NotMultipleValueType
BadDataFromTaggingUI
AmbiguousTerm
InlineEditNotSupportedWithMultipleTermSets
ErrorTermStoreNotFound

ResolveUnboundTerm

AmbiguousTerm
ClosedTermSetError
ErrorTermStoreNotFound

ResolveBoundTerm

AmbiguousTerm
ClosedTermSetError

AddNewKeyword

ErrorDuplicatedUnavailableTerm
TermSetNotAvailableOrOpenForTermCreation
TermNotValid

AddNewTerm TermStoreDefaultKeywordsNotSet

It is easy to find the real validation error messages using a code like this:

  1. private void ResourceStringTest()
  2. {
  3.     String[] resourceNames = new String[] {
  4.         "TermNotValid",
  5.         "NotMultipleValueType",
  6.         "BadDataFromTaggingUI",
  7.         "InlineEditNotSupportedWithMultipleTermSets",
  8.         "ErrorTermStoreNotFound",
  9.         "AmbiguousTerm",
  10.         "ClosedTermSetError",
  11.         "TermStoreDefaultKeywordsNotSet",
  12.         "ErrorDuplicatedUnavailableTerm",
  13.         "TermSetNotAvailableOrOpenForTermCreation"
  14.     };
  15.  
  16.     Array.ForEach(resourceNames, resourceName => Console.WriteLine("{0}: {1}", resourceName, GetResourceString(resourceName)));
  17.  
  18. }
  19.  
  20. private String GetResourceString(String resourceName)
  21. {
  22.     String resourceString = String.Empty;
  23.  
  24.     // hack to get the Microsoft.SharePoint.Taxonomy assembly
  25.     Assembly taxonomy = typeof(TaxonomyField).Assembly;
  26.     // Resources is an internal class, so you cannot get it directly by defining the type from Visual Studio
  27.     Type resourcesType = taxonomy.GetType("Microsoft.SharePoint.Taxonomy.Internal.Resources");
  28.  
  29.     Type[] parameterTypes = new Type[1] { typeof(String) };
  30.     MethodInfo mi_GetString = resourcesType.GetMethod("GetString", BindingFlags.NonPublic | BindingFlags.Static,
  31.         null, parameterTypes, null);
  32.     if (mi_GetString != null)
  33.     {
  34.         resourceString = (String)mi_GetString.Invoke(null, new object[] { resourceName });
  35.     }
  36.  
  37.     return resourceString;
  38.  
  39. }

And it is the formatted result of the run:

TermNotValid The given term is not valid
NotMultipleValueType This field does not allow multiple values
BadDataFromTaggingUI The data returned from the tagging UI was not formatted correctly
AmbiguousTerm There is more than one match for your term. Please disambiguate which term you would like to use
InlineEditNotSupportedWithMultipleTermSets Inline adding not supported with multiple term sets
ErrorTermStoreNotFound The term store could not be accessed.
ClosedTermSetError Creating a new value is not allowed in this field, please select from the existing terms.
ErrorDuplicatedUnavailableTerm The term used is unavailable for tagging.  Please select a new term
TermSetNotAvailableOrOpenForTermCreation Term set not available or open for term creation
TermStoreDefaultKeywordsNotSet The site does not contain a default keywords termstore

You can see that it is sometimes trivial to guess the short form of the warning from the full error message (and vice versa), but in some cases it would be hard to guess without this little trick.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: