嗨,大家好,我是C#的新手,使用以下代码,我得到文件使用错误。如果我双击资源管理器中的ISO文件,它将打开。如果可以手动打开ISO,不确定我在这里缺少什么?为什么我的代码没有打开它?
代码:
private void btnOpenISO_Click(object sender, EventArgs e)
{
listBox2.Items.Clear();
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = Path.GetPathRoot(Environment.SystemDirectory);
openFileDialog1.Filter = "ISO files (*.iso)|*.iso|All files (*.*)|*.*";
openFileDialog1.Multiselect = false;
openFileDialog1.FilterIndex = 1;
openFileDialog1.ShowDialog();
using (FileStream fs = File.Open(openFileDialog1.FileName, FileMode.Open))
{
CDReader cd = new CDReader(fs, true, true);
foreach (var dir in cd.Root.GetDirectories())
{
listBox2.Items.Add(dir.Name);
// Console.WriteLine(dir.Name);
}
}
}