如何在系统中获得驱动器('C'或'E'或'F')?

时间:2014-08-20 19:18:11

标签: c#-4.0 wix bootstrapper wix3.7

我正在开发一个Bootstrapper应用程序。当我们转到安装位置选择向导时,我们可以使用浏览选项来更改安装位置。

当我们计算浏览选项时,我只需要显示系统中可用的驱动器(' C' D'和' F')。当我们选择驱动器时,它不会扩展。我需要在安装向导中的安装位置文本中单独使用该驱动器(例如:C :)。

有人可以指导我如何达到我的要求吗?

我的代码:

private void btn_Browse_Click(object sender, EventArgs e)
{
  txt_InstallLocation.Focus();
  FBD_Source.RootFolder = Environment.SpecialFolder.Desktop;

  if (FBD_Source.ShowDialog() == DialogResult.OK)
  {
    txt_InstallLocation.TextBox.Text = FBD_Source.SelectedPath;
    BA.Model.Bootstrapper.Engine.StringVariables["APPDIR"] = FBD_Source.SelectedPath + "\\";
  }
}

我需要修改下面的代码行。

FBD_Source.RootFolder = Environment.SpecialFolder.Desktop;

有人可以帮助我继续前进或指导我走正确的道路吗?

1 个答案:

答案 0 :(得分:0)

您可以找到这样的可用驱动器。

var drives = System.Environment.GetLogicalDrives();
foreach (string d in drives)
       Console.WriteLine(d);

不要使用FolderBrowserDialog 使用动态创建的单选按钮/列表创建表单,并让用户选择其中一个选项

像这样的东西

        var drives = System.Environment.GetLogicalDrives();

        Form selectionForm = new Form() { MaximizeBox = false, FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog, StartPosition = FormStartPosition.CenterScreen };


        ListBox lb = new ListBox() { Dock = DockStyle.Fill };
        foreach (var item in drives)
            lb.Items.Add(item);
        selectionForm.Controls.Add(lb);

        Button btnOk = new Button() { Dock = DockStyle.Left, Width = selectionForm.Width / 2 };
        btnOk.Text = "OK";
        Button btnCancel = new Button() { Dock = DockStyle.Right, Width = selectionForm.Width / 2 };
        btnCancel.Text = "Cancel";


        Panel bottomPanel = new Panel() { Dock = DockStyle.Bottom, Height = 50 };

        bottomPanel.Controls.Add(btnOk);
        bottomPanel.Controls.Add(btnCancel);
        selectionForm.Controls.Add(bottomPanel);
        selectionForm.ShowDialog();
        MessageBox.Show(lb.SelectedItem.ToString());