通用对话框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;


}

 

 

posted @ 2013-04-25 20:56  Predator  阅读(158)  评论(0编辑  收藏  举报