OpenFileDialog.OpenFile 方法
http://msdn.microsoft.com/zh-cn/library/system.windows.forms.openfiledialog.openfile%28VS.80%29.aspx
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
http://msdn.microsoft.com/zh-cn/library/system.windows.forms.openfiledialog.openfile%28VS.80%29.aspx
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
Sample:
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);
}
}
}
如: private void button1_Click(object sender, EventArgs e)
{
if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
string path = this.folderBrowserDialog1.SelectedPath;
MessageBox.Show(path + "");
}
}
{
if (openFileDialog1.FileName != "openFileDialog1")
textBox1.Text = openFileDialog1.FileName;
}