简体   繁体   中英

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:

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?

试试下面的代码

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

Try to provide filter like this. I used it to filter PDFs. it should work.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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