我想从here获取一个基本的文件对话框示例,并且在'OK'上出现错误,我不知道为什么。'System.Nullable <bool>'不包含'OK'的定义
错误1'System.Nullable'不包含'OK'的定义,并且没有找到接受'System.Nullable'类型的第一个参数的扩展方法'OK'(您是否缺少using指令集引用?)
private void button1_Click(object sender, System.EventArgs e)
{
Stream myStream = null;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
using (myStream)
{
// Insert code to read the stream here.
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
}
你打开文件对话框什么组件可从? – 2010-08-17 15:06:15
这个工作,你可以更具体一点?错误可能不在这里... – jeroenh 2010-08-17 15:06:22