content category
Hello waqar,
Please take a look at this post.
Best wishes,
Ivan Dimitrov
the Telerik team
Hello!..
Thanks for reply.
Code is working but it returns duplicate images.
private TaxonomyPropertyDescriptor GetPropertyDescriptor(Type itemType, ITaxon taxon)
return TaxonomyManager.GetPropertyDescriptor(itemType, taxon);
private IEnumerable GetItems(ITaxon taxon, ContentDataProviderBase contentProvider, Type itemType)
TaxonomyPropertyDescriptor prop = GetPropertyDescriptor(itemType, taxon);
int? totalCount = 0;
var items = contentProvider.GetItemsByTaxon(taxon.Id, prop.MetaField.IsSingleTaxon, prop.Name, itemType, string.Empty, string.Empty, 0, 100, ref totalCount);
return items;
void Check_taxon(Taxon T)
var taxonomyManager = TaxonomyManager.GetManager();
var taxonGuidId = T.Id;
ITaxon taxon = taxonomyManager.GetTaxon(taxonGuidId);
string itemTypeName = "Telerik.Sitefinity.Libraries.Model.Image";
Type itemType = Telerik.Sitefinity.Utilities.TypeConverters.TypeResolutionService.ResolveType(itemTypeName);
var manager = Telerik.Sitefinity.Data.ManagerBase.GetMappedManager(itemType, "");
ContentDataProviderBase contentProvider = manager.Provider as ContentDataProviderBase;
IEnumerable IE = GetItems(taxon, contentProvider, itemType);
foreach (Telerik.Sitefinity.Libraries.Model.Image CI in IE)
string Title = CI.Title;
How can escape from the duplication. I have to retrieve a number images so please suggest some thing which work quicker.
Plz reply ASAP.
Thnaks!
Hi waqar,
These are not duplicate images. The code returns all content items no matter of the content status, because inside GetItemsByTaxon the filter is set to null. You can get the master item by using the filter parameter of GetItemsByTaxon
private
IEnumerable GetItems(ITaxon taxon, ContentDataProviderBase contentProvider, Type itemType)
TaxonomyPropertyDescriptor prop = GetPropertyDescriptor(itemType, taxon);
int
? totalCount = 0;
var filter =
"Status = Master"
;
var items = contentProvider.GetItemsByTaxon(taxon.Id, prop.MetaField.IsSingleTaxon, prop.Name, itemType, filter,
string
.Empty, 0, 100,
ref
totalCount);
return
items;
my way to get content category, it seems not related to this post. But if you understand how to get content category, you may understand how to get content by category. Tested in Sitefinity 5.1 version. Hope it helps.
//tipitem is my content which is get from DB already
var categoryId = TipItem.GetValue<TrackedList<Guid>>("Category").FirstOrDefault();
var manager = TaxonomyManager.GetManager();
//tipcategory is string type which I use in UI for displaying
TipCategory = manager.GetTaxa<HierarchicalTaxon>().Single(t => t.Id == categoryId).Name;