我正在尝试使用我创建的自定义文件格式向我的OpenFileDialog添加过滤器这是我到目前为止所拥有的:
private void btnSymKey_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "public key (*.publ)";
openFileDialog1.FilterIndex = 2;
if (openFileDialog1.ShowDialog() == true)
{
DecryptionPathes.encryptedKey = System.IO.Path.GetFullPath(openFileDialog1.FileName);
txtSymKeyPath.Text = DecryptionPathes.encryptedKey;
this.btnSafeDecrypt.Visibility = Visibility.Visible;
this.btnSafeDecrypt.IsEnabled = true;
this.txtSafeDecryptPath.Visibility = Visibility.Visible;
}
}
但这不起作用,因为OpenFileDialog不知道“.publ”还有办法过滤这些文件吗?
答案 0 :(得分:1)
尝试以下代码
openFileDialog1.Filter = "public key (*.publ)|*.publ";
答案 1 :(得分:0)
尝试提供这样的过滤器。我用它来过滤PDF。它应该工作。
openFileDialog1.openFileDialog1.Filter = "publ Files|*.publ";