文件夹浏览器对话框从远程机器的角度,像SSMS使用的一样 [英] Folder Browser Dialog from remote machine perspective like the one SSMS uses

查看:157
本文介绍了文件夹浏览器对话框从远程机器的角度,像SSMS使用的一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个维护工具,我需要让用户为新的数据库选择文件位置。我将使用FolderBrowserDialog,除了我想从SQL Server实际运行的机器的角度向用户显示目录结构,而不是从该工具运行的客户端。

I'm creating a maintenance tool and I need to let the user to select a file location for new databases. I would use the FolderBrowserDialog except that I want to show the user the directory structure from the point of view of the machine that SQL Server is actually on rather than the client the tool is being run from.

我知道SSMS会在选择备份位置时执行此操作,所以我想知道它使用的对话框是否可用,或者是否有一种方法使FolderBrowserDialog以这种方式运行。看起来当你通过SMSS来做,你可以绕过某些权限问题(即服务器不需要共享或任何东西)。

I know SSMS does this whenever you are selecting backup locations, so I'm wondering if the dialog it uses is available or if there's a way to make the FolderBrowserDialog behave in this manner. It seems that when you do it through SMSS you get to bypass certain permissions issues (i.e. the server doesn't need to be shared or anything).

建议? p>

Suggestions?

推荐答案

我一直在做类似的任务,遇到同样的问题。
我很高兴地分享了现成的解决方案,但是我和魔鬼签了合同,公司拥有我为他们工作所做的一切。
但是它的要点是这样的:

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:


  1. 使用 Server.EnumAvailableMedia 方法来获取服务器上的硬盘驱动器。

  2. 调用xp_dirtree存储过程获取给定路径中的文件和子目录

  1. Use the Server.EnumAvailableMedia method to get the hard drives on the server.
  2. Call the xp_dirtree stored procedure to get the files and sub-directories in the given path

我最终使用TreeView制作了自己的文件对话窗体。填充它的代码应该如下所示:

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());
    }
}

这篇关于文件夹浏览器对话框从远程机器的角度,像SSMS使用的一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆