Wix安装程序中的“文件浏览”对话框



我正在使用Wix安装程序v3.9创建一个安装程序。我想在安装完成后弹出一个"文件浏览"对话框。用户可以从一个目录中选择多个文件。然后,这些文件路径必须作为命令行参数传递给exe。我该怎么做?Wix浏览器Dlg只允许选择目录。

感谢您的帮助。

据我所知,wix工具集没有任何文件浏览控件。所以我通常使用c#自定义操作来完成这项工作。

试试这个样品,并根据您的需要进行定制。

using WinForms = System.Windows.Forms;
using System.IO;
using Microsoft.Deployment.WindowsInstaller;
[CustomAction]
public static ActionResult OpenFileChooser(Session session)
{
    try
    {
        session.Log("Begin OpenFileChooser Custom Action");
        var task = new Thread(() => GetFile(session));
        task.SetApartmentState(ApartmentState.STA);
        task.Start();
        task.Join();
        session.Log("End OpenFileChooser Custom Action");
    }
    catch (Exception ex)
    {
        session.Log("Exception occurred as Message: {0}rn StackTrace: {1}", ex.Message, ex.StackTrace);
        return ActionResult.Failure;
    }
    return ActionResult.Success;
}
private static void GetFile(Session session)
{
    var fileDialog = new WinForms.OpenFileDialog { Filter = "Text File (*.txt)|*.txt" };
    if (fileDialog.ShowDialog() == WinForms.DialogResult.OK)
    {
        session["FILEPATH"] = fileDialog.FileName;
    }
}

最新更新