日期:2014-05-18 浏览次数:21058 次
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);
}
}
}
------解决方案--------------------
http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog_methods.aspx
请问你查出来有 OpenFiles 在哪里???
或者你直接说你想用 OpenFiles 做什么?(假设OpenFiles存在)。
------解决方案--------------------