【发布时间】:2013-07-25 09:09:30
【问题描述】:
我创建了一个 OpenFileDialog 对象,名为 openFileDialog。
调用 openFileDialog.ShowDialog 时,我希望能够选择只有扩展名 ".abc" 而不是 ".abcd" 的文件。
使用属性:
this.openFileDialog.Filter = "*.abc";
不起作用。也可以选择“.abcd”文件。
这里是完整的代码:
var openFileDialog = GetOpenFileDialog("abc",
"*.abc",
"anything (*.abc)|*.abc",
"Select abc file to import...");
if (openFileDialog.ShowDialog() == DialogResult.OK)
{ DoJob(); }
GetOpenFileDialog 在哪里:
private OpenFileDialog GetOpenFileDialog(string defaultExt, string fileName, string filter, string title)
{
return new OpenFileDialog
{
DefaultExt = defaultExt,
FileName = fileName,
Filter = filter,
Title = title,
};
}
如果有任何帮助,我将不胜感激。谢谢!
【问题讨论】:
-
还有一个类似的帖子[这里][1] [1]:stackoverflow.com/questions/437914/…
标签: c# winforms filter filtering openfiledialog