簡體   English   中英

Wix安裝程序中的“文件瀏覽”對話框

[英]File Browse Dialog in Wix Installer

我正在使用Wix Installer v3.9創建安裝程序。 安裝完成后,我想彈出“文件瀏覽”對話框。 用戶可以從目錄中選擇多個文件。 然后,這些文件路徑必須作為命令行參數傳遞給exe。 我怎樣才能做到這一點? Wix BrowseDlg僅允許選擇目錄。

任何幫助表示贊賞。

據我所知,wix工具集沒有任何文件瀏覽控件。 所以我通常使用c#自定義操作來完成這項工作。

嘗試此示例並根據您的需要對其進行自定義。

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