Before a new term can be used for tagging in a web site it needs to be added to the hidden list "TaxonomyHiddenList".
Several suggestions how to add a new term with code has been posted and this is my conclusion:
Adding a new term to an item:
TaxonomyField tf = item.Fields["ColumnName"] as TaxonomyField;
tf.SetFieldValue(item,term);
item.Update();
This doesn´t work for new items:
int hiddenTermId = -1;
int[] wssIds = TaxonomyField.GetWssIdsOfTerm(site, TermStore.Id, TermSet.Id, Term.Id, false, 1);
if(wssIds.Length > 0)
hiddenTermId = wssIds[0];
TaxonomyFieldValue tfv = new TaxonomyFieldValue(termId + ";#" + term.Name + TaxonomyField.TaxonomyGuidLabelDelimiter + term.Id.ToString())
or this:
string termString = String.Concat("-1", SPFieldMultiColumnValue.Delimiter, term.GetDefaultLabel(1033));
TaxonomyFieldValue tfv = new TaxonomyFieldValue(termString);
Add a comment if you have any question.
Showing posts with label metadata. Show all posts
Showing posts with label metadata. Show all posts
Monday, 1 November 2010
Wednesday, 14 May 2008
Why BDC columns doesn´t work in Office / Doc Mgmt
Using BDC columns in document libraries feels as a great option, but when trying to use it for any serious document management (using mostly OOB functions) it fails for the following reasons:
1. A BDC column can not be used as a field reference in Word. If you want to display information in header or footer the field reference can not be used.
2. The BDC column can not be configured as a site column (MacroView is workaround, but it can not be edited from the DIP). Major drawback to any usage of content types.
4. If you click the refresh button in the document library all your documents will be checked out again.
We are developing a workaround based on "Choice" columns and eventhandlers instead.
BDC on the other hand is great if you want to display information in web parts :)
1. A BDC column can not be used as a field reference in Word. If you want to display information in header or footer the field reference can not be used.
2. The BDC column can not be configured as a site column (MacroView is workaround, but it can not be edited from the DIP). Major drawback to any usage of content types.
4. If you click the refresh button in the document library all your documents will be checked out again.
We are developing a workaround based on "Choice" columns and eventhandlers instead.
BDC on the other hand is great if you want to display information in web parts :)
Subscribe to:
Posts (Atom)