【问题标题】:File Browse Dialog in Wix InstallerWix 安装程序中的文件浏览对话框
【发布时间】:2016-05-10 11:45:12
【问题描述】:

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

感谢任何帮助。

【问题讨论】:

    标签: wix windows-installer wix3.9


    【解决方案1】:

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

    试试这个示例并根据您的需要进行自定义。

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

    【讨论】:

    • 这太棒了!!如何在从中调用 BrowseFile 的 CustomDialog 的文本框中显示选定的路径?
    • 文本框的值应为 [PropertyName]。这将确保反映在属性中的值是同步的,反之亦然。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-01
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    相关资源
    最近更新 更多