简体   繁体   English

如何在C#WPF中使用OpenFileDialog过滤自定义格式

[英]How to filter a custom format with the OpenFileDialog in c# WPF

I'm trying to add a filter to my OpenFileDialog with a custom file format that I created This is what I have so far: 我正在尝试使用我创建的自定义文件格式将过滤器添加到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;
        }
    }

But this doesnt work since the OpenFileDialog doesn't know ".publ" is there still a way to filter these files? 但这是行不通的,因为OpenFileDialog不知道“ .publ”是否仍然可以过滤这些文件?

试试下面的代码

openFileDialog1.Filter = "public key  (*.publ)|*.publ";

Try to provide filter like this. 尝试提供这样的过滤器。 I used it to filter PDFs. 我用它来过滤PDF。 it should work. 它应该工作。

openFileDialog1.openFileDialog1.Filter = "publ Files|*.publ";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM