Forums / Developing with Sitefinity / New Catgeories added not displaying

New Catgeories added not displaying

6 posts, 0 answered
  1. Karl
    Karl avatar
    44 posts
    Registered:
    18 Jun 2009
    15 Nov 2011
    Link to this post
    Hi,

    I'm having a couple of problems with the displaying of categories. I'm using the following code to display catgeories

    var manager = new LibraryManager();
    var list = Categories.Select(category => manager.GetCategory(new Guid(category.Key))).ToList();
     
       foreach (Telerik.Cms.Engine.ICategory test  in list)
                {
                    if (test != null)
                    {
     
                        Response.Write(test. + "<BR>");
                    }
                    else
                    {
                        Response.Write(test.Application + "<BR>");
                    }
                }

    The for loop is just for testing,. This is bound to a radtreeview.

    The orginally problem I had was when I associated a document to a category and later deleted the category I would get this error Object reference not set to an instance of an object. When I try and display the test.CategoryName.

    I added the if statement around it which gets rid of the error, and displays the categories. When I add any new catgoeirs they do not display, even if I associated a document to it.

    Could you please help as this is quite urgent.

    Thanks

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16051 posts
    Registered:
    24 Sep 2012
    15 Nov 2011
    Link to this post
    Hello Karl,

    Categories are associated with content objects. Do you have all categories associated with a content item?

    Regards,
    Ivan Dimitrov
    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
  3. Karl
    Karl avatar
    44 posts
    Registered:
    18 Jun 2009
    15 Nov 2011
    Link to this post
    Hi,

    When I go to create a category I select the Docmuent Library and then the category menu appears on the left. I then add a category.
    Is this what you mean?

    Thanks
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16051 posts
    Registered:
    24 Sep 2012
    15 Nov 2011
    Link to this post
    Hi Karl,

    GetCategory returns single category. You are also using some LINQ expression with ToList  at the end which is highly not recommendable. .ToList() is an extension method from the System.Linq namespace, which invokes the List type constructor with the instance parameter. This means that using "instance.ToList()" is equivalent to using "new List<T>(instance)" where T is the type. So every time when .ToList() is called you are creating a new list of objects, which is stored into the memory. This is dangerous especially in cases when given collection have a lot of elements. So avoid calling .ToList() when you have this option otherwise you should double check the risk every time when you are using .ToList() method.

    You are making queries against Categories, so make sure that the elements you build have all properties set. You can make a simple check by using our API and calling GetCategory("string name") method of ContentManager class by passing the provider with with the manager will be initialized.

    Greetings,
    Ivan Dimitrov
    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
  5. Karl
    Karl avatar
    44 posts
    Registered:
    18 Jun 2009
    17 Nov 2011
    Link to this post
    Hi,

    Thanks for getting back to me, how would I bind/query a category and display all the associated categories? Are there any examples?

    When I use any of the examples on this page:
    http://www.sitefinity.com/help/developer-manual/categories-get.html

    It always brings back the categories for News Module.

    Thanks
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16051 posts
    Registered:
    24 Sep 2012
    17 Nov 2011
    Link to this post
    Hi Karl,

    Metadata is set per provider. I suppose that you are passing News provider instead the provider for which you want to get the metadata.

    Best wishes,
    Ivan Dimitrov
    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
Register for webinar
6 posts, 0 answered