简体   繁体   English

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

[英]File Browse Dialog in Wix Installer

I am using Wix Installer v3.9 to create a setup. 我正在使用Wix Installer v3.9创建安装程序。 I want to pop a File Browse dialog after the Installation gets completed. 安装完成后,我想弹出“文件浏览”对话框。 User can select multiple files from a directory. 用户可以从目录中选择多个文件。 Then those file paths have to pass as command line arguments to an exe. 然后,这些文件路径必须作为命令行参数传递给exe。 How can I do this? 我怎样才能做到这一点? The Wix BrowseDlg lets select directory only. Wix BrowseDlg仅允许选择目录。

Any help is appreciated. 任何帮助表示赞赏。

As far as I know,wix toolset doesn`t have any file browse control. 据我所知,wix工具集没有任何文件浏览控件。 So I normally use c# Custom Action to do this job. 所以我通常使用c#自定义操作来完成这项工作。

Try this sample and customize it according to your need. 尝试此示例并根据您的需要对其进行自定义。

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}\r\n 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;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM