Wix 安装程序中的文件浏览对话框 [英] File Browse Dialog in Wix Installer

查看:31
本文介绍了Wix 安装程序中的文件浏览对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Wix Installer v3.9 来创建设置.我想在安装完成后弹出一个文件浏览对话框.用户可以从一个目录中选择多个文件.然后这些文件路径必须作为命令行参数传递给 exe.我怎样才能做到这一点?Wix BrowseDlg 只允许选择目录.

I am using Wix Installer v3.9 to create a setup. 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. How can I do this? The Wix BrowseDlg lets select directory only.

感谢任何帮助.

推荐答案

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

As far as I know,wix toolset doesn`t have any file browse control. So I normally use c# Custom Action to do this job.

试用此示例并根据您的需要对其进行自定义.

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

这篇关于Wix 安装程序中的文件浏览对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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