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 retrieve the selected TaxonomyField value that the user selects from the TaxonomyWebTaggingControl rather than just a string representation. The idea being to eventually create a TaxonomyFieldValue object from that result. i.e.

string selectedTaxonomyTerm = this.TaxonomyWebTaggingControl.Text; // represents the selected term's Label | Guid

TaxonomyFieldValue taxonomyFieldValue = TaxonomyFieldControl.GetTaxonomyValue(selectedTaxonomyTerm); // Converts to a TaxonomyFieldValue object, however ValidateString throws exception because no TaxonomyField is assigned.

// what i want
var selectedTaxonomyField = this.TaxonomyWebTaggingControl.Field // Get the selected Field 
var newTaxonomyValue = new TaxonomyFieldValue(selectedTaxonomyField);
newTaxonomyValue.PopulateFromLabelGuidPair(selectedTaxonomyTerm);

So basically i want a way to retrieve the underlying TaxonomyField from the selection of the TaxonomyWebTaggingControl. Any help would be great.

share|improve this question
add comment

2 Answers

Just get the field from the list and then cast it to a TaxonomyField like this:

SPListItem item = ...;
TaxonomyField taxField = item.Fields["FieldName"] as TaxonomyField;
TaxonomyFieldValue taxFieldValue = new TaxonomyFieldValue(taxField);
taxFieldValue.PopulateFromLabelGuidPair(taxonomyCtrl.Text);
share|improve this answer
    
+1 I would probably use list.Fields intead of item.Fields –  Jorge Carvalho Oct 9 '11 at 14:27
add comment

I like Wictor's answer and already vote it up. But it might not fit your question, so I'll add my 2 cents here too.

Another approach you might want to explore, if you're looking for a more abstract way of putting this in the control, could be to go through the TaxonomyHiddenList, look for a term based on your label, and get all the information you need from the TaxonomySession. Is it worth the extra trouble? What is your scenario?

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.