本文介绍了.acc音频文件确实在OpenFileDialog框中检测到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我打开对话框以选择音频文件时,可以看到和选择除".acc"以外的所有内容..以下是我的代码..

when i open dialog box to select audio file''s everything except ".acc" can be seen and selected.. Following is my code..

{   System.Windows.Forms.OpenFileDialog os = new System.Windows.Forms.OpenFileDialog();

   os.Filter = "Audio (*.mp3,*.acc,*wma)|*.acc;*.mp3;*.wma|All Files (*.*)|*.*";
   os.FilterIndex = 1;
   System.Windows.Forms.DialogResult result = os.ShowDialog();

   if (result == System.Windows.Forms.DialogResult.OK)
   {   os.Dispose();
       string[] path = os.FileNames;
       for (int j = 0; j < path.Length; j++)
        {
          string s=path[j];
         if(s.Contains(".acc")) // 2nd if
           {
               MessageBox.Show("yes it contain");
           }
         }
  }

       this.Activate();
       this.Topmost = true;
       this.Topmost = false;
       this.Focus();

}//end


当我选择该时间的所有文件时,即使文件是.acc,它也不会进入第2个
预先


when i choose all Files that time it is seen but again it does not enter into 2nd if even if file is .acc

推荐答案

System.Windows.Forms.OpenFileDialog os = new System.Windows.Forms.OpenFileDialog
    {
        Filter = "Audio (*.cs,*.acc,*wma)|*.cs;*.mp3;*.wma|All Files (*.*)|*.*",
        Multiselect = true,
        FilterIndex = 1
    };
var result = os.ShowDialog();

if (result == System.Windows.Forms.DialogResult.OK)
{
    foreach (var file in os.FileNames)
    {
        if (System.IO.Path.GetExtension(file) == ".cs") // 2nd if
        {
            MessageBox.Show("yes it contain");
        }
    }
}
os.Dispose();



因为通常建议这样做,所以我使用了对象初始化器,并且还使用Path类来获取扩展名.

当您丢弃if语句内的对话框时,您犯了一个严重的错误.这意味着,如果DialogResult不正确,则不会丢弃DialogBox.大不对.



I used the object initializer since that generally is recommended, and also use the Path class to get the extension.

You made a real serious mistake when you disposed of the dialog box inside the if statement. This meant that if the DialogResult was not "OK" you did not dispose of the DialogBox. Big no no.


这篇关于.acc音频文件确实在OpenFileDialog框中检测到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 01:24