Server Folder/File Structure in Treeview

10 posts, 1 answers
  1. Kurosh
    Kurosh avatar
    5 posts
    Member since:
    May 2011

    Posted 14 Jun 2011 Link to this post

    I've just started evaluating the telerik radcontrols for silverlight and so far I am very impressed. I have run into an issue and I was hoping that someone could help me resolve this.

    Problem: I need to traverse through folders and files located in a folder under the root of a web application and populate the radtreeview based on folder/file names. Populating the treeview is not an issue as I will be doing that in the code behind. However I am not sure about accessing the server folder/file structure and getting the paths and folder/file names.

    Any help would be greatly appreciated and thanks in advance.
    -Kurosh
  2. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 17 Jun 2011 Link to this post

    Hello Kurosh,


    I prepared a sample for which uses WCF RIA Services. I created a service method that iterates over a Folder in the WebSolution and returns a HIerarchy of Objects ( ObservableCollection<DataItems>) that is used in the client to show a hierarchical data in the RadTreeView. Please examine the solution and let us know if it helped you.

    Regards,
    Petar Mladenov
    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
  3. DevCraft banner
  4. Kurosh
    Kurosh avatar
    5 posts
    Member since:
    May 2011

    Posted 17 Jun 2011 Link to this post

    Much Thanks! Your solution worked like a charm.

    Cheers!
    Kurosh
  5. Chandu
    Chandu avatar
    23 posts
    Member since:
    Jul 2012

    Posted 12 Sep 2012 Link to this post

    Hello Petar,

    I have Worked on your sample, its working fine and i am having one issue, I need to traverse through folders and files located in a folder and inside of that folder up to the last traverse. 
    Below is the scenario for my requirement.
    Ex: Folder1-->Folder2-->Folder3-->Folder4-->FileName I need to traverse upto folder N..

    Thanks in Advance

  6. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 17 Sep 2012 Link to this post

    Hello Chandu,

     The following recursive code should do the work, no changes in XAML (SL project):

    private DirectoryInfo startDirectory = new DirectoryInfo(@"C:\Users\pmladenov\Desktop\279102_TreeViewFoldersInWebPart\TreeViewFolders.Web\FolderA");
            private string startDirectoryString = "FolderA";
            public void DoWork()
            {
            }
     
            public ObservableCollection<DataItem> GetSomeData()
            {
                if (startDirectory != null)
                {
                    ObservableCollection<DataItem> collection = new ObservableCollection<DataItem>();
                    DataItem dataItem = new DataItem() { Name = startDirectoryString };
                    this.AddChildCollection(dataItem, startDirectory);
                    collection.Add(dataItem);
                    return collection;
                }
                return null;
            }
     
            private void AddChildCollection(DataItem dataItem, DirectoryInfo currDirectory)
            {
                foreach (DirectoryInfo item in currDirectory.GetDirectories())
                {
                    DataItem child = new DataItem()
                    {
                        Name = item.Name.ToString()
                    };
                    this.AddChildCollection(child, new DirectoryInfo(item.FullName));
                    dataItem.Children.Add(child);
                }
            }

    Regards,
    Petar Mladenov
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

  7. Chandu
    Chandu avatar
    23 posts
    Member since:
    Jul 2012

    Posted 17 Sep 2012 Link to this post


    Many many thanks petar,it is working perfect

    thanks a lot
  8. Pablo
    Pablo avatar
    2 posts
    Member since:
    Jul 2013

    Posted 03 Dec 2014 in reply to Petar Mladenov Link to this post


    I have a question
    to view files in the trewview

    Carpeta_SubCarpeta_SubSubCarpeta_NombreArchivo  how I can do
  9. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 05 Dec 2014 Link to this post

    Hi Pablo,

    I am not sure I completely understand this scenario. The RadTreeView provides ItemTemplateSelector ItemContainerStyleSelector which allows you to set different templates / styles on the different levels.
    If this does not answer your question, is it possible for you to open a new support thread with more details about your specific scenario. Thank you in advance.

    Regards,
    Petar Mladenov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  10. Pablo
    Pablo avatar
    2 posts
    Member since:
    Jul 2013

    Posted 05 Dec 2014 in reply to Petar Mladenov Link to this post

    OK sorry atacch example   of What I want to do whit wcf  whit RadTreView
  11. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 09 Dec 2014 Link to this post

    Hi Pablo,

    In your picture I can see a File / Folder tree structure and that is why I have attached a sample project implementing such structure with RadTreeView. Let us know if this is your requirement.

    Regards,
    Petar Mladenov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
DevCraft banner