content category

Posted by Community Admin on 03-Aug-2018 14:19

content category

All Replies

Posted by Community Admin on 11-Jan-2011 00:00

Hello!
I am having two categories with the name to Exterior and Interior and I wrote following code to get contents inside the category.

 var taxonomyManager = TaxonomyManager.GetManager();
 var c = "categories";
 var taxonomy1 = taxonomyManager.GetTaxonomies<HierarchicalTaxonomy>().Where(t => t.Name == c).SingleOrDefault();
var b = taxonomy1.Taxa.Where(t => t.Name == "Interior").SingleOrDefault();    
var contents = App.WorkWith().ContentItems().Where(ci => ((IList<Guid>)ci.GetValue("Category")).Contains(b.Id)).Get();
contents.Count();///***** Here the error occurs******////

threw an exception of type 'Telerik.OpenAccess.Exceptions.QueryException'
base Telerik.OpenAccess.OpenAccessException: "line 1:173: expecting \"TOK_UNSIGNED_INTEGER\", found '2.' (\"2.\" is a reserved word.)\r\nOriginal Query: DEFINE EXTENT extnt FOR Telerik.Sitefinity.GenericContent.Model.ContentItem; SELECT COUNT(*) FROM extnt AS t1 WHERE t1.appName = $1 AND EXISTS x IN t1.Category : ( x = $2.id )"


Please let me that is it a kind of bug or any thing wrong from my side. Please reply ASAP.
and also suggest how can I do this task.

Thanks!

Posted by Community Admin on 11-Jan-2011 00:00

Hello waqar,

Please take a look at this post.

Best wishes,
Ivan Dimitrov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 12-Jan-2011 00:00

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!

Posted by Community Admin on 12-Jan-2011 00:00

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;
       


All the best,
Ivan Dimitrov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 18-Jun-2013 00:00

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;

   

This thread is closed