I've been working on a similar task, and came across the same problem. I would happily share the ready solution, but I signed a deal with the devil, and the company owns everything I make while working for them. But the gist of it is this:
- Use the Server.EnumAvailableMedia method to get the hard drives on the server.
- Call the xp_dirtree stored procedure to get the files and sub-directories in the given path
I ended up making my own file dialog Form using a TreeView. The code that populates it should look something like:
public partial class RemoteFileDialog : Form
{
public Server server = new Server( new ServerConnection("ServerName", "User", "Password") );
/* ... */
public void getServerDrives()
{
DataTable d = server.EnumAvailableMedia();
foreach (DataRow r in d.Rows)
treeView.Nodes.Add( new TreeNode(r["Name"].ToString() );
}
/* ... */
//populate a node with files and subdirectories when it's expanded
private void treeView_BeforeExpand(object sender, TreeViewCancelEventArgs e)
{
DataSet ds = server.ConnectionContext.ExecuteWithResults(string.Format("exec xp_dirtree '{0}', 1, 1", e.Node.FullPath));
ds.Tables[0].DefaultView.Sort = "file ASC"; // list directories first, then files
DataTable d = ds.Tables[0].DefaultView.ToTable();
foreach (DataRow r in d.Rows)
e.Node.Nodes.Add( new TreeNode(r["subdirectory"].ToString());
}
}