如何使用 C# WPF 中的 OpenFileDialog 过滤自定义格式
How to filter a custom format with the OpenFileDialog in c# WPF
我正在尝试使用我创建的自定义文件格式向我的 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”是否还有过滤这些文件的方法?
尝试提供这样的过滤器。我用它来过滤 PDF。它应该工作。
openFileDialog1.openFileDialog1.Filter = "publ Files|*.publ";
试试下面的代码
openFileDialog1.Filter = "public key (*.publ)|*.publ";
我正在尝试使用我创建的自定义文件格式向我的 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”是否还有过滤这些文件的方法?
尝试提供这样的过滤器。我用它来过滤 PDF。它应该工作。
openFileDialog1.openFileDialog1.Filter = "publ Files|*.publ";
试试下面的代码
openFileDialog1.Filter = "public key (*.publ)|*.publ";