File Browse Dialog in Wix Installer

给你一囗甜甜゛ 提交于 2020-01-27 08:31:49

问题


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.

Any help is appreciated.


回答1:


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


来源:https://stackoverflow.com/questions/37137579/file-browse-dialog-in-wix-installer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!