Applying TreeView to Documents&Files - General Discussions - General Discussions - Progress Community
 General Discussions

Applying TreeView to Documents&Files

  • Applying TreeView to Documents&Files
  • Need some assistance in setting up a widget to show the libraries and documents in TreeView similar to this link below, is this possible?

     

    demos.telerik.com/.../defaultcs.aspx
  • Hi Hector,

    I have added a modified code of the sample provided here:
    http://www.sitefinity.com/developer-network/forums/general-discussions-/modifying-download-list-widget
    to suit your scenario for document libraries and folders, and the documents themselves:
    public IEnumerable<LibraryTreeModel> GetDocumentLibrariesAndFolders()
            
                LibrariesManager manager = new LibrariesManager();
     
                var albums = manager.GetDocumentLibraries();
     
                var data = new List<LibraryTreeModel>();
     
                foreach (var item in albums)
                
                    var children = manager.GetAllFolders(item);
                    var model = new LibraryTreeModel();
                    model.Title = item.Title.ToString();
                    model.Id = item.Id;
                    model.ParentId = (item.ParentId == null) ? null : item.ParentId;
                    data.Add(model);
                    foreach (var child in children)
                    
                        var modelChild = new LibraryTreeModel();
                        modelChild.Title = child.Title.ToString();
                        modelChild.MediaUrl = child.Title.ToString();
                        modelChild.Id = child.Id;
                        modelChild.ParentId = child.ParentId;
                        data.Add(modelChild);
                    
                
     
                List<LibraryTreeModel> models = new List<LibraryTreeModel>();
     
                foreach (var item in data)
                
                    // For folders
                    IQueryable<Telerik.Sitefinity.Libraries.Model.Document> docsFolders = manager.GetDocuments()
                        .Where(img => img.FolderId == item.Id && img.Status == ContentLifecycleStatus.Live);
     
                    // If folder is actually a Library
                    IQueryable<Telerik.Sitefinity.Libraries.Model.Document> docsLibraries = manager.GetDocuments()
                        .Where(img => img.Parent != null && img.Parent.Id == item.Id && img.FolderId == null && img.Status == ContentLifecycleStatus.Live);
     
                    IQueryable<Telerik.Sitefinity.Libraries.Model.Document> allDocs = docsFolders.Concat(docsLibraries);
                    foreach (var file in allDocs)
                    
                        var modelChild = new LibraryTreeModel();
                        modelChild.Title = file.Title.ToString();
                        modelChild.Id = file.Id;
                        modelChild.ParentId = item.Id;
                        modelChild.MediaUrl = file.MediaUrl;
                        models.Add(modelChild);
                    
                
     
                IEnumerable<LibraryTreeModel> ds = models.Concat(data);
     
                return ds;
            

    Control Initialize controls:
    protected override void InitializeControls(GenericContainer container)
            
                var data = this.GetDocumentLibrariesAndFolders();
     
                TreeView.DataFieldParentID = "ParentId";
                TreeView.DataFieldID = "Id";
                TreeView.DataTextField = "Title";
                TreeView.DataValueField = "Title";
                TreeView.DataSource = data;
                TreeView.DataBind();
            

    Model and template changes:
    <%@ Control Language="C#" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
     
    <telerik:RadTreeView ID="RadTreeView" runat="server" Width="300px" Height="250px">
        <NodeTemplate>
            <div>
                <a href='<%# DataBinder.Eval(Container.DataItem, "MediaUrl") %>'><%# DataBinder.Eval(Container.DataItem, "Title") %></a>
            </div>
        </NodeTemplate>
    </telerik:RadTreeView>
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.Sitefinity;
     
    namespace SitefinityWebApp.LibraryTreeView
        public class LibraryTreeModel
        
            public string Title get; set;
     
            public Guid? ParentId get; set;
     
            public Guid Id get; set;
     
            public string MediaUrl get; set;
       
        


    Note that the above code queries all the documents and folder/libraries on init. You might consider make this on demand if you have many folders and document, so it will perform better.

    Regards,
    Nikola Zagorchev
    Telerik
     
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • Thanks Nikola! 

     

    Two questions. Is there a way to show only the libraries the logged in user has access to? Also when I click on the library itself it takes me to back to the homepage, is that normal? Once again thanks for your assistance with this! 

  • Hi Hector,

    The permissions should be applied automatically by the manager when the queries are made and when clicking on a document, you should not be able to download it or view it, if you do not have permissions. Please, check the Url set to the link when you are being redirected to the home page, I am not reproducing this on my end.

    Regards,
    Nikola Zagorchev
    Telerik
     
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • 7b42511e-37c1-6deb-a958-ff0000446526_error.png

    Hi Nikola,

     

    That is correct. The files that a user does not have access to it does not let me download them it gives me the page in the image attached. What I am asking is if its possible to not show those libraries at all when the user logs in and just show the libraries that the user has access to.

  • Hi Hector,

    If the user does not have access to the library, at all, this should be handled by the manager (if you are not suppressing security). If they can view the library, just not the documents the library will be returned from the query.
    You can also try enabling the filtering by view permissions globally or per provider. You can set that for the application in Advanced settings -> Security -> Enable filtering queries by view permissions.

    Regards,
    Nikola Zagorchev
    Telerik
     
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • Nikola,

    I already have that setting applied to filter queries by view permission but when I login with a user who doesn't have access to a specific album i can still see it and its content. However, it does not let me download the content, what I want is to not show the library the the user does not have access to at all in the TreeView.

    Thanks,

     Hector Rodriguez

  • Hello Hector,

    Could you please check the "View document library" permission set globally for the documents and files and "View this document library" for the particular library permission? Let us know and the "View document" permission set. If the first two are set for everyone, for instance, you would be able to get the libraries. Check also whether you are not manually suppressing security checks or using elevated mode region.

    Regards,
    Nikola Zagorchev
    Telerik
     
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • Hello Nikola,

    The permission settings for "Documents & Files" is set to "Everyone" but the actual individual libraries are set to only "View document library" and "View document" based on a specific role which is what I want. In the regular downloads list widget it is set like this and it shows me only the documents of the library that the user role has access to. There is no way to show the parent library and sub library that documents are in using the download list widget is there? something similar to how "Documents and Files" is shown on the back-end because if there is that would be great seeing as permission wise it works wonderfully. 

     

    Thanks,

    Hector Rodriguez

  • Hello Hector,

    You can access the Document Library using the Document property:
    public DocumentLibrary Library

    The folder can be queried using the FolderId
    public Guid? FolderId


    Regards,
    Nikola Zagorchev
    Telerik
     
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • Imports System.IO.DirectoryInfoImports System.IO Partial Class treeview1 Inherits System.Web.UI.PageProtected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load'\\PFS1-DATA\Epic Implementation\CIS Corner\Tip Sheets 'set the initial Value of the TreeNode to the C drive, but we will change this on Page LoadTreeview1.Nodes(0).Value = Server.MapPath("tipsheets")End SubProtected Sub Treeview1_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles Treeview1.TreeNodePopulateIf IsCallback = True ThenIf e.Node.ChildNodes.Count = 0 ThenLoadChildNode(e.Node)End IfEnd IfEnd SubPrivate Sub LoadChildNode(ByVal node As TreeNode)Dim directory As DirectoryInfo directory = New DirectoryInfo(node.Value)For Each subtree As DirectoryInfo In directory.GetDirectories()Dim subNode As TreeNode = New TreeNode(subtree.Name) subNode.Value = subtree.FullNameTryIf subtree.GetDirectories().Length > 0 Or subtree.GetFiles().Length > 0 Then subNode.SelectAction = TreeNodeSelectAction.SelectExpand subNode.PopulateOnDemand = True subNode.NavigateUrl = "#"End IfCatch ex As ExceptionEnd Try node.ChildNodes.Add(subNode)NextFor Each fi As FileInfo In directory.GetFiles()Dim subNode As TreeNode = New TreeNode(fi.Name) node.ChildNodes.Add(subNode) subNode.NavigateUrl = "tipsheets/" & directory.Name.ToString & "/" & fi.Name.ToString()'If hosting this web application on a server, you will want to use the Server.MapPath line that is currently commented out below. 'subNode.NavigateUrl = Server.MapPath(fi.Name.ToString())NextEnd SubEnd Class
  • Hi Angela,

    Could you please specify what you are trying to achieve and what error you are experiencing, so we can assist further?

    Regards,
    Nikola Zagorchev
    Telerik
     
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items