2012-12-06 88 views
1

我想實現的是從OpenFileDialog同時選擇多個文件夾和文件
設置的建議的解決方案:擴展OpenFileDialog同時選擇文件夾和文件

OpenFileDialog.Multiselect = true; 
OpenFileDialog.ValidateNames = false; 
OpenFileDialog.CheckFileExists = false; 
OpenFileDialog.CheckPathExists = true; 
OpenFileDialog.FileName = "Dummy"; 
OpenFileDialog.Filter = string.Empty; 

對使用​​情況,此設置失敗,當用戶選擇的文件夾和文件同時

我要尋找一個解決方案通過,當用戶按下開放按鈕,我可以關閉對話框,並獲得路徑選擇的文件(S)和文件夾(S)。

回答

0

我認爲這個問題已經回答了here

我重複一遍:

如果使用文件名屬性,而不是FileName屬性,你會得到一個字符串數組選擇每個文件,使用shift鍵選擇多個文件。像這樣:

private void button1_Click(object sender, EventArgs e) 
{ 
    OpenFileDialog x = new OpenFileDialog(); 
    x.Multiselect = true; 
    x.ShowDialog(); 
    string[] result = x.FileNames; 

    foreach (string y in result) 
     MessageBox.Show(y, "Selected Item", MessageBoxButtons.OK, MessageBoxIcon.Information); 
} 

文件和文件夾,你需要使用CommonOpenFileDialog附帶​​,特定類是here

+0

dialog.FileNames給我所選文件的字符串[],但不包括使用對話框選擇的文件夾(bin)和文件(MainWindow.Xaml.cs)(來自上面的屏幕截圖)的內容。 –

+0

文件名字符串[]數組包含選定的每個文件的路徑。至於文件夾的內容,我必須嘗試檢查它,順便說一句,有幾個自定義的DialogBoxes可能適合您的使用,說這一個:https://github.com/scottwis/OpenFileOrFolderDialog –

+0

不適用於我的用例因爲不允許mutli選擇 –

相關問題