tags:

views:

441

answers:

2

Is there a component available list FileUpload which shows files on the server, not the client?

I am basically looking for a clean dialog box to select server side files, like the one used in FileUpload.

+1  A: 

Nope. There's not. That said, you can use a listbox, and load the files into it.

public sub file_DatabindListbox(directoryPath as string)
   for each fName as string in io.directory(directorypath).getfilenames()
     dim li as new listitem 
     li.text = io.path.getfilename(fName)
     li.value = fName
     myFileListbox.Items.Add(li)
   next
end sub
Stephen Wrighton
Not exactly good for navigating to other directories
Brettski
typically, an end user shouldn't be navigating different directories on your web server. But, you could use trees, and the list view to build a windows explorer type web page.
Stephen Wrighton
A: 

You cannot browse through the folders of your server in the same way that you would with the FileUpload components, because... well all the files are located on the server and the "clean dialog" that you refer to is client side. You can write you own code to list the files in a dropdown. But if your files are located in multiple folder and you would like to keep some structure, a TreeView might do the trick with something like this:

protected void Page_Load(object sender, EventArgs e)
{
     SetChildFolders(trvFiles.Nodes, @"C:\MyFolder");
}

    private void SetChildFolders(TreeNodeCollection nodes, string path)
    {
     foreach (string directory in Directory.GetDirectories(path))
     {
      DirectoryInfo dirInfo = new DirectoryInfo(directory);
      TreeNode node = new TreeNode(dirInfo.Name, dirInfo.FullName);

      SetChildFolders(node.ChildNodes, dirInfo.FullName);
      SetChildFiles(node.ChildNodes, dirInfo.FullName);

      trvFiles.Nodes.Add(node);
     }
    }

    private void SetChildFiles(TreeNodeCollection nodes, string path)
    {
     foreach (string file in Directory.GetFiles(path))
     {
      FileInfo fileInfo = new FileInfo(file);
      nodes.Add(new TreeNode(fileInfo.Name, fileInfo.FullName));
     }
    }

You can ofcourse style the treeview in many many ways.

Jacob T. Nielsen
Thank you, yes I understand the current one is client side ; I was just hoping there was one which was showing remote files.
Brettski