我正在使用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();
原文地址:https://www.jb51.cc/csharp/97249.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。