More in this section

Forums / Developing with Sitefinity / How to get all news categories programatically.

How to get all news categories programatically.

8 posts, 0 answered
  1. sathiyaseelan
    sathiyaseelan avatar
    82 posts
    Registered:
    26 Aug 2008
    02 Dec 2011
    Link to this post
    I am using sitefinity 4.3. I need a code to get all news categories. I cannot able to get this in forum section.
  2. sathiyaseelan
    sathiyaseelan avatar
    82 posts
    Registered:
    26 Aug 2008
    02 Dec 2011
    Link to this post
    Can u pls suggest ASAP.
  3. sathiyaseelan
    sathiyaseelan avatar
    82 posts
    Registered:
    26 Aug 2008
    02 Dec 2011
    Link to this post
    Any reply pls...
  4. sathiyaseelan
    sathiyaseelan avatar
    82 posts
    Registered:
    26 Aug 2008
    02 Dec 2011
    Link to this post
    Hey man any reply...
  5. sathiyaseelan
    sathiyaseelan avatar
    82 posts
    Registered:
    26 Aug 2008
    05 Dec 2011
    Link to this post
    Hey guys,

    Can you reply for this..We are using your product which has to be supported properly. There are too many issue's guys.
    How you are able to release like this??
  6. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    05 Dec 2011
    Link to this post
    Hi Sathiyaseelan,

    As per your license agreement our support services are offered from Monday till Friday which excludes Saturday and Sunday. Also the guaranteed response time for your license is 72h which includes the forum type of conversation. More information about the support plans can be found here.

    In order to achieve the desired scenario you need to get all categories and see which one of them is used in the news items. You can refer to our documentation and especially the section regarding the hierarchical taxonomies:

    http://www.sitefinity.com/40/help/developers-guide/sitefinity-essentials-taxonomies-hierarchical-taxonomies-hierarchical-taxonomy-api.html

    http://www.sitefinity.com/40/help/developers-guide/sitefinity-essentials-taxonomies-associating-items-with-taxa.html

    You can also use the following code:

    var dataItem = App.WorkWith().News().Get().Where(p => p.Title == Newsitemtitle).First();
    var propDesc = OrganizerBase.GetProperty(dataItem.GetType(), "Category") as TaxonomyPropertyDescriptor;
    if (propDesc != null)
    {
        var taxonIds = propDesc.GetValue(dataItem) as IList<Guid>;
        var taxonomyManager = TaxonomyManager.GetManager();
        var taxa = new List<string>();
        foreach (var taxonId in taxonIds)
        {
            taxa.Add(taxonomyManager.GetTaxon(taxonId).Title);
        }
    }


    Regards,
    Victor Velev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. sathiyaseelan
    sathiyaseelan avatar
    82 posts
    Registered:
    26 Aug 2008
    06 Dec 2011
    Link to this post
    Hello,

    I found it by digging. Your reply was not good enough still.
                /* List of all categories */
                Telerik.Sitefinity.Taxonomies.TaxonomyManager manager1 = Telerik.Sitefinity.Taxonomies.TaxonomyManager.GetManager();
                IList categoryList = manager1.GetTaxa<Telerik.Sitefinity.Taxonomies.Model.HierarchicalTaxon>()
                                        .Where(t => t.Taxonomy.Title == "Categories")
                                        .Select(t =>
                                            new { Id = t.Id, Name = t.Title.ToString() })
                                        .OrderByDescending(t => t.Name)
                                        .ToList();

    How to get the categories associated to a particular news by passing News ID..? Can I get at-least  an answer for this.

    Thanks,
  8. Tim
    Tim avatar
    258 posts
    Registered:
    22 Jun 2011
    06 Dec 2011
    Link to this post
    Sathiyaseelan,

    This post will help you. I've tested the code and know it works.

    Hope that helps!
8 posts, 0 answered