【问题标题】:How to filter a custom format with the OpenFileDialog in c# WPF如何在 c# WPF 中使用 OpenFileDialog 过滤自定义格式
【发布时间】:2018-02-16 10:24:17
【问题描述】:

我正在尝试使用我创建的自定义文件格式向我的 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”是否还有过滤这些文件的方法?

【问题讨论】:

  • 好的,我应该阅读例外情况......你必须写“你的文字 |*.yourFormat;”

标签: c# wpf openfiledialog


【解决方案1】:

试试下面的代码

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

【讨论】:

    【解决方案2】:

    尝试提供这样的过滤器。我用它来过滤PDF。它应该工作。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-20
      • 1970-01-01
      • 1970-01-01
      • 2017-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-18
      相关资源
      最近更新 更多