0

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?

2 Answers2

1

Try below code

openFileDialog1.Filter = "public key  (*.publ)|*.publ";
A. S. Mahadik
  • 517
  • 1
  • 4
  • 14
0

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

openFileDialog1.openFileDialog1.Filter = "publ Files|*.publ";
Sachin Trivedi
  • 1,872
  • 3
  • 24
  • 53