请教 打开文件对话框 问题。。
请问 打开文件对话框 弹出后,用户输入了不存在的文件名,如何去做提示??private void button5_Click(object sender, EventArgs e)
{
openFileDialog1.InitialDirectory = @"c:\";
openFileDialog1.Title = "选择文件";
openFileDialog1.FileName = "";
openFileDialog1.Filter = "Text files(*.txt)|*.txt";
openFileDialog1.FilterIndex = 1;
if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
{
if (!File.Exists(openFileDialog1.FileName))
MessageBox.Show("文件不存在!");
else
textBox1.Text = openFileDialog1.FileName;
}
else
textBox1.Text = "No File.";
}
这样写编译不过,红字部分。。请大家帮忙。。。