2016-05-10 56 views
1

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

任何幫助表示讚賞。

回答

3

據我所知,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; 
    } 
} 
相關問題