通用对话框OpenFileDialog
OpenFileDialog
private FileStream OpenFile()
{
// Displays an OpenFileDialog and shows the read/only files.
OpenFileDialog dlgOpenFile = new OpenFileDialog();
dlgOpenFile.ShowReadOnly = true;
if(dlgOpenFile.ShowDialog() == DialogResult.OK)
{
// If ReadOnlyChecked is true, uses the OpenFile method to
// open the file with read/only access.
if(dlgOpenFile.ReadOnlyChecked == true)
{
return (FileStream)dlgOpenFile.OpenFile();
}
// Otherwise, opens the file with read/write access.
else
{
string path = dlgOpenFile.FileName;
return new FileStream(path, System.IO.FileMode.Open,
System.IO.FileAccess.ReadWrite);
}
}
return null;
}