c# – 如何使CommonOpenFileDialog仅选择文件夹,但仍显示文件?
发布时间:2020-12-15 18:00:47 所属栏目:百科 来源:网络整理
导读:我正在使用Microsoft的 CommonOpenFileDialog来允许用户选择一个文件夹,但是当对话框出现时,不会显示任何文件.当IsFolderPicker设置为true时,是否可以显示文件以及文件夹? 我当前的代码看起来像这样 var dialog = new CommonOpenFileDialog();dialog.IsFold
我正在使用Microsoft的
CommonOpenFileDialog来允许用户选择一个文件夹,但是当对话框出现时,不会显示任何文件.当IsFolderPicker设置为true时,是否可以显示文件以及文件夹?
我当前的代码看起来像这样 var dialog = new CommonOpenFileDialog(); dialog.IsFolderPicker = true; if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { SelectedFolderPath = dialog.FileName; } 解决方法
在我头顶,这是我做的
var dialog = new CommonOpenFileDialog { EnsurePathExists = true,EnsureFileExists = false,AllowNonFileSystemItems = false,DefaultFileName = "Select Folder",Title = "Select The Folder To Process" }; dialog.SetOpenButtonText("Select Folder"); if (dialog.ShowDialog() == CommonFileDialogResult.Ok) dirToProcess = Directory.Exists(dialog.FileName) ? dialog.FileName : Path.GetDirectoryName(dialog.FileName); 编辑:神圣2年前蝙蝠侠! 似乎几乎没有变化,下面的片段似乎做了这个工作 var openFolder = new CommonOpenFileDialog(); openFolder.AllowNonFileSystemItems = true; openFolder.Multiselect = true; openFolder.IsFolderPicker = true; openFolder.Title = "Select folders with jpg files"; if (openFolder.ShowDialog() != CommonFileDialogResult.Ok) { MessageBox.Show("No Folder selected"); return; } // get all the directories in selected dirctory var dirs = openFolder.FileNames.ToArray(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |