每次都忘記都要找,所以直接貼上來,
其實只是內建的說明而已 XD
Text files (*.txt)|*.txt|All files
(*.*)|*.*
Image
Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*
Excel files (*.xls)|*.xls|All files (*.*)|*.*
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);
}
}
}
沒有留言:
張貼留言