Hi friends,
I need to view files and folders which is available in remote system directory using FTP connection. I established a connction to the remote system usign FTP. but i dont know how to view the files and folders as a tree structure format. that tree structure like.
-root directory
+sub directory
- subdirectory
-file
-file
if any one know the possible solutions please do let me know..
thanks,
regards
sasi
Loading

Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Jul 22, 2011, 4:19 AM EDT
I guess you are getting the collection of folders and files from FTP.
If so,
Look into this.
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 22, 2011, 4:30 AM EDT
Are you building Windows Forms or Web application?
Zoran
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 22, 2011, 6:48 AM EDT
If you're developing Windows Forms application, then solution which is based on the same FtpClient as in your previous post can be easily developed. I've appended ZIP containing source code for the form which lets you enter FTP address and credentials and it populates the TreeView control.
Basically, solution is in this function:
private void PopulateTreeViewRecursively(FTPclient cli, TreeNode parentNode)
{
string curDir = cli.CurrentDirectory;
FTPdirectory dirContent = cli.ListDirectoryDetail(curDir);
FTPdirectory subdirs = dirContent.GetDirectories();
Hashtable dirsVisited = new Hashtable();
foreach (FTPfileInfo file in subdirs)
{
dirsVisited.Add(file.Filename, null);
cli.CurrentDirectory = file.FullName;
TreeNode node = new TreeNode(file.Filename.ToUpper());
if (parentNode != null)
parentNode.Nodes.Add(node);
else
tvDirectories.Nodes.Add(node);
PopulateTreeViewRecursively(cli, node);
}
foreach (FTPfileInfo file in dirContent)
if (!dirsVisited.ContainsKey(file.Filename))
{
TreeNode node = new TreeNode(file.Filename);
if (parentNode != null)
parentNode.Nodes.Add(node);
else
tvDirectories.Nodes.Add(node);
}
if (parentNode != null)
parentNode.Expand();
}
This function is quite similar to the function which was printing nodes on Console, only this time data are added to the TreeView.
The project attached is created in Visual Studio 2008, but should be convertible to other versions of VS if needed.
Zoran
Sasikumar S29 reputationPosted Jul 22, 2011, 9:36 AM EDT
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 22, 2011, 12:58 PM EDT
Zoran
Sasikumar S29 reputationPosted Jul 23, 2011, 6:02 AM EDT
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 25, 2011, 5:26 AM EDT
Zoran
Sasikumar S29 reputationPosted Jul 25, 2011, 11:54 PM EDT
Steve Omor2 reputationPosted Sep 8, 2011, 11:22 AM EDT
chirag shah2 reputationPosted Oct 8, 2014, 10:27 AM EDT
Were you able to find one for Web Application?
Thanks,
Chirag
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 26, 2011, 12:59 AM EDT
Zoran