.acc音频文件确实在OpenFileDialog框中检测到 [英] .acc audio file do detect in OpenFileDialog box
问题描述
当我打开对话框以选择音频文件时,可以看到和选择除".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个
预先 thankx
when i choose all Files that time it is seen but again it does not enter into 2nd if even if file is .acc
thankx in advance
推荐答案
首先,该代码似乎可以正常工作.不知道你的问题是什么.由于我没有.acc,因此将我正在寻找的文件类型更改为".cs".另外,由于您不关心文件列表(Filenames
)而不是Filename
,因此我将multiselect设置为true:
First of all, the code seems to work fine. Don''t know what your problem is. I changed the file type I was looking for to ".cs" since I have no .acc. Also since you were bothering with the list of files (Filenames
) instead ofFilename
, I set multiselect to true:
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框中检测到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!