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


}

 

 

转载于:https://www.cnblogs.com/ganquanfu2008/archive/2013/04/25/3043508.html

你可能感兴趣的:(通用对话框OpenFileDialog)