文件夹浏览器对话框像打开文件对话框 [英] Folder browser dialog like open file dialog
问题描述
请参阅下面的快照。这是从新项目创建工作流在Visual Studio 2008年拍摄
Please see the snapshot below. This was taken from "New project creation" workflow in Visual Studio 2008.
用于选择在该项目将被存储在文件夹此窗口。如何在我的C#应用程序创建一个类似的窗口?
This window is used for selecting a folder in which the project will be stored. How do I create a similar window in my c# application?
推荐答案
这是Office类似的东西,一个对话框,允许选择一个文件夹。
,唯一不同的是,选择文件夹按钮,命名为OK,而不是选择文件夹。
It is something similar in Office, a dialog which allows to select a folder. The only difference is that the Select folder button is named "OK" instead of "Select folder".
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Core.FileDialog fileDialog = app.get_FileDialog(Microsoft.Office.Core.MsoFileDialogType.msoFileDialogFolderPicker);
fileDialog.InitialFileName = "c:\\Temp\\"; //something you want
int nres = fileDialog.Show();
if (nres == -1) //ok
{
Microsoft.Office.Core.FileDialogSelectedItems selectedItems = fileDialog.SelectedItems;
string[] selectedFolders = selectedItems.Cast<string>().ToArray();
if (selectedFolders.Length > 0)
{
string selectedFolder = selectedFolders[0];
}
}
当然,你需要将引用添加到微软。 Office.Core(如Microsoft Office 14.0对象库)和的Microsoft.Office.Interop.Excel(Microsoft Excel中14.0对象库)。
Of course, you need to add references to Microsoft.Office.Core (Microsoft Office 14.0 Object Library) and Microsoft.Office.Interop.Excel (Microsoft Excel 14.0 Object Library).
这篇关于文件夹浏览器对话框像打开文件对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!