Adding tag to Document not working
I'm trying to add tags to a document programmatically using the examples (http://www.sitefinity.com/40/help/developers-guide/sitefinity-essentials-taxonomies-associating-items-with-taxa.html), but it's not quite working.
Here's my code:
var taxonId =
new
Guid(
"d349c5b0-a23e-4c44-8415-5f44617e0f72"
);
var documentId =
new
Guid(
"22d9dd0e-4db3-44bd-8d36-38bfe1664177"
);
var libManager = LibrariesManager.GetManager();
var doc = libManager.GetDocument(documentId);
doc.Organizer.AddTaxa(
"Tags"
, taxonId);
libManager.SaveChanges();
Hello David,
Please accept our sincere apologies for the inconvenience caused. I have successfully reproduced the mentioned behavior, and indeed the tags get added to the content item properly, however they are not displayed in the backend Libraries. I have logged a bug in our system, and we'll be working on providing a fix for it for the upcoming releases. Your Telerik points have been updated accordingly.
Regards,
Boyan Barnev
the Telerik team
Is there a PITS number I can track?
Thanks,
David
Hi David,
Currently the issue is added for fixing in Q3 release and it is set with higher priority. The issue is logged in our internal system and we have not exposed PITS for it at this stage.
Best wishes,
Ivan Dimitrov
the Telerik team
Hi Ivan,
Thanks for the reply. This is almost a showstopper for us, as we rely on setting the tags (and categories) for our documents. Is there a workaround using the database? I can't figure out which database table isn't being populated.
Thanks again,
David
Hello David,
I've escalated the problem and we will try to fix it for one of the first internal builds that we will make available for 4.2. This issue will go for sure in 4.2 SP1, which is tentatively scheduled for mid of September.
Kind regards,Thank you.
Hello David,
Just a quick follow-up: we have just tested the functionality in our latest officially supported version (Sitefinity 4.2) and everything seems to be working properly. One important thing, that I might have missed mentioning lat time, is that you'll have to make sure that you're not applying the Tag to a state of the document that is not the master state, in which case you won't have it displayed in the backend, since what you see when you click on a documents under Content->Documents and Files is a draft copy created from the master copy of the document. The below sample code will properly assign a tag to your documents, please try it out and let us know if any issues persist.
var taxManager = TaxonomyManager.GetManager();
var taxon = taxManager.GetTaxa<FlatTaxon>().Where(t => t.Name ==
"Test"
).Single();
LibrariesManager libManager = LibrariesManager.GetManager();
var myDocument = libManager.GetDocuments().Where(d => d.Title ==
"ChatLog Issues"
);
foreach
(var doc
in
myDocument)
doc.Organizer.AddTaxa(
"Tags"
, taxon.Id);
libManager.SaveChanges();
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
Thanks for the follow-up. I had actually found this same solution while working on a couple other document issues. (This was after upgrading to 4.2.)
Thanks again,
David