简体   繁体   中英

File Browse Dialog in Wix Installer

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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