My server have drives and folders hierarchy.i need to see all the files,folders and that subfolders on the server like treeview formate for downloading.I am able to connect to server.

please help me.

asked 22 Oct '10, 12:40

Neha's gravatar image

Neha
16
accept rate: 0%


You can easily construct a tree made of TreeNode objects yourself by calling Ftp object's GetList method repeatedly. Just use a method like this one:

    public static TreeNode GetListTree(Ftp ftp, string folder)
    {
        // create a tree node
        TreeNode node = new TreeNode(folder);

        // save current folder
        string originalFolder = ftp.GetCurrentDirectory();

        // change current directory to the next folder
        ftp.ChangeDirectory(folder);

        // get list of files in the current folder
        FtpList list = ftp.GetList();

        // iterate through the list of files
        foreach (FtpItem item in list)
        {
            TreeNode subNode;
            if (item.IsDirectory)
            {
                // if an item is a directory, construct
                // a tree for it recursively
                subNode = GetListTree(ftp, item.Name);
            }
            else
            {
                // if an item is not a directory,
                // just add it to the tree
                subNode = new TreeNode(item.Name);
            }

            // add the subnode to current node's nodes
            node.Nodes.Add(subNode);
        }

        // go back to the original folder
        ftp.ChangeDirectory(originalFolder);

        return node;
    }

Call this on the folder you wish to appear in the TreeView and add the result to TreeView's Nodes collection.

link

answered 22 Oct '10, 14:21

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.4k28
accept rate: 31%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×152

Asked: 22 Oct '10, 12:40

Seen: 717 times

Last updated: 25 Mar '11, 21:23