1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Displaying documents by category tree

Displaying documents by category tree

11 posts, 2 answered
  1. Jean-Paul Smit
    Jean-Paul Smit avatar
    8 posts
    Registered:
    13 Dec 2009
    01 Jan 2010
    Link to this post
    I'm researching Sitefinity as a possible option for my portal.
    So far everything looks great.
    For my portal the document library section is very important.
    I want a document library for every registered user so they get their own document library.
    I guess that is not a problem since everything is in the database.
    Then I would like to have the documents displayed in a tree-like view, based on the category tree for the document.
    I tried to use the standard category tree control, but that displayed no result at all.
    Is my requested functionality possible out of the box?
    If not, what would be the easiest approach of developing this?

    Thanks in advance,
    Jean-Paul
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    04 Jan 2010
    Link to this post
    Hi Jean-Paul Smit,

    I want a document library for every registered user so they get their own document library.

    The built in module does not support permissions per library. You can extend this functionality and implement permissions per role. You have to map the external template LibraryListView.ascx and create a code behind of it where you get access to the repeater that shows all libraries.

    protected void allLibraries_ItemDataBound(object sender, RepeaterItemEventArgs e)
      {
          if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
          {
              ILibrary library = e.Item.DataItem as ILibrary;
              if(library != null && library.Name == "Documents" && UserManager.IsCurrentUserInRole("SomeVisitors"))
              {
                  HtmlGenericControl libraryPanel =(HtmlGenericControl)e.Item.FindControl("libraryPanel");
                  libraryPanel.Visible = false;
              }
          }
      }

    The best option here is using ILibrary object and its Owner property to restrict the unauthorized access.
    Displaying the items in a tree will be more complicated, but in this case you will have a flat structure, because you will not have parent and children nodes. You will have just one level. This will require to replace the default view. There are required controls,  so you have to remove them and implement the whole logic by your own, because you have to use a completely different control - RadTreeView.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Jean-Paul Smit
    Jean-Paul Smit avatar
    8 posts
    Registered:
    13 Dec 2009
    04 Jan 2010
    Link to this post
    Hi Ivan,

    Thanks for your reply!
    Every day I notice there is more to learn about the capabilities of Sitefinity.
    The document library per logged on user should only be shown on the live site.
    The maintainers of the site are allowed to see all document libraries.
    So I create a library in the modules section and show the contents in a custom user control, based on the name of the logged on user.
    So far so good. (it is increadibly easy to add a user control by the way :-) )

    I understand I have to implement the tree control myself and that is ok.
    However, I have difficulties retrieving the tags and categories that are linked to a document.
    Can you help me with that?

    Thanks,
    Jean-Paul
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    04 Jan 2010
    Link to this post
    Hello Jean-Paul Smit,

    The following sample code gets all tags for a specific content item

    var contentManager = new Telerik.Cms.Engine.ContentManager("Libraries");
    IList allitems = contentManager.GetContent();
    if (allitems .Count > 0)
    {
       Telerik.Cms.Engine.IContent thirdContent = contentManager.GetContent(((Telerik.Cms.Engine.IContent)listOfContentItems[0]).ID);
       IList itemTags = contentManager.GetTags(thirdContent.ID);
       if (itemTags .Count > 0)
       {
           
       }
    }

    Another option is working with TaggedContent property of ITag object

    var manager = new ContentManager("Libraries");
    IList contentItems = manager.GetContent();
    IList allTags = manager.GetTags();
    foreach (ITag tag in allTags)
    {
        IList taggedContent = tag.TaggedContent;
        {
              foreach (ITaggedContent tgdCnt in taggedContent)
             {
                  IContent content = manager.GetContent(tgdCnt.ContentID);
                   if (content != null)
                   {
                         .....
                   }
             }
        }
    }


    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  5. Jean-Paul Smit
    Jean-Paul Smit avatar
    8 posts
    Registered:
    13 Dec 2009
    11 Jan 2010
    Link to this post
    Hi Ivan,

    I managed to get all tags for a certain document from a certain document library.
    My next step would be to find out what category the document is assigned to.
    Do you happen to have a code sample for this?

    Thanks in advance,
    Jean-Paul
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    11 Jan 2010
    Link to this post
    Hello Jean-Paul Smit,

    Here is a sample code that shows getting the category associated with an content item

    var cntManager = new ContentManager("Generic_Content");
    IContent cntitem = cntManager.GetContent(new Guid("154DA723-39A4-4d22-8B94-ABD44942A088"));
    string categoryName = (string)cntitem.GetMetaData("Category");

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  7. Jean-Paul Smit
    Jean-Paul Smit avatar
    8 posts
    Registered:
    13 Dec 2009
    13 Jan 2010
    Link to this post
    Ok, great, I'm getting closer and closer :-)
    I tried to create a category structure, with the same structure for different root nodes. I want to create a document structure with a year as a root. Unfortunately it doesn't seem te be possible to have multiple categories or subcategories with the same name.
    My solution was to add a tag representing the year, and then select a category to indicate the location in the structure.
    So far so good.
    I looked at the category structure as is shown in the Modules section for documents. I would like to have the same sorting order in my custom user control.
    Can you push me in the right direction with some code?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    13 Jan 2010
    Link to this post
    Hello Jean-Paul Smit,

    You can use GetContent method and its overloads which support sorting as parameters. You can gather more information at Finding Content Items.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Jean-Paul Smit
    Jean-Paul Smit avatar
    8 posts
    Registered:
    13 Dec 2009
    14 Jan 2010
    Link to this post
    Hi Ivan,

    I'm still having difficulties implementing my requirements.
    I tried to figure out how you build the category tree in the admin - modules - documents & libraries section, but with no luck.
    Because that is exactly what I need, I would like to ask you if you can help me pointing where to find the code or maybe with a sample?

    Thanks in advance,
    Jean-Paul
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    14 Jan 2010
    Link to this post
    Hello Jean-Paul Smit,

    The following sample will build hierarchical RadTreeView which nodes are Libraries categories.

    var manager = new ContentManager("Libraries");
    IList allcats = manager.GetCategories();
    this.RadTreeView1.DataTextField = "CategoryName";
    this.RadTreeView1.DataFieldID = "ID";
    this.RadTreeView1.DataValueField = "ID";
    this.RadTreeView1.DataFieldParentID = "ParentCategoryID";
    this.RadTreeView1.DataSource = allcats;
    this.RadTreeView1.DataBind();
     
    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  11. Jean-Paul Smit
    Jean-Paul Smit avatar
    8 posts
    Registered:
    13 Dec 2009
    15 Jan 2010
    Link to this post
    Thanks a lot!
Register for webinar
11 posts, 2 answered