Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Vault Folder Structure in Treeview

1 REPLY 1
Reply
Message 1 of 2
chaturvedi.ankit1986
831 Views, 1 Reply

Vault Folder Structure in Treeview

Hi Can someone guide how to populate a Treeview such as the Folder Structure in Vault Explorer. I tried using the following recursive method to get the folders but I am unable to populate a treeview

private void PrintFilesInFolder(Folder parentFolder, WebServiceManager serviceManager)
        {
            
            // check for any sub Folders.
            Folder[] folders = serviceManager.DocumentService.GetFoldersByParentId(
                parentFolder.Id, false);
            if (folders != null && folders.Length > 0)
            {
                foreach (Folder folder in folders)
                {
                    foldertreeview.Nodes[count].Nodes.Add(folder.Name);
                    // recursively print the files in each sub-Folder
                    PrintFilesInFolder(folder, serviceManager);
                }
                count++;
            }            
        }  

 Can someone please guide me how to populate a treeview. I have populated a treeview with the windows directory structure and it was working perfectly fine but I dont have much idea how to do it in Vault. Thanks in advance

Tags (3)
1 REPLY 1
Message 2 of 2

Hi, you basically need a recursion where you pass the current folder and current TreeView node. For every cycle you can get the child folders, add them to the tree and recall the same function with the according child folder and child node.

here is a sample for the recursion done in PowerShell
function FillTreeVieew($folder, $node)
{
$folders = $vault.DocumentService.GetFoldersByParentId($folder.Id, $false)
if($folders -eq $null) {return}
foreach ($folder in $folders) {
$childNode = $node.Nodes.Add($folder.Name)
FillTreeVieew -folder $folder -node $childNode
}
}

as you can see i get the next level of children. For each children i add it to the list of nodes and then recall "myself" with the folder and node. This is a very trivial implementation, but works. Just call the function one time with the root folder and the root Node, and the rest will be done by the recursion.

However, this approach is not really performing. You will make lots of calls to Vault in order to fill up the complete TreeView although maybe just some elements are needed.
Therefore i would suggest to implement the OnBeforeExpand event, and pull the child folders only when the specific branch gets expanded. In order to display the + in front the node, you may add a dummy entry, which you delete before filling up with children. This ends up having always a + in front of nodes, but it reduces the server calls.

hope this helps

ciao
marco



coolOrange
www.coolorange.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report