This documentation is archived and is not being maintained.

OpenFileDialog.ShowReadOnly Property

Gets or sets a value indicating whether the dialog box contains a read-only check box.

[Visual Basic]
Public Property ShowReadOnly As Boolean
[C#]
public bool ShowReadOnly {get; set;}
[C++]
public: __property bool get_ShowReadOnly();
public: __property void set_ShowReadOnly(bool);
[JScript]
public function get ShowReadOnly() : Boolean;
public function set ShowReadOnly(Boolean);

Property Value

true if the dialog box contains a read-only check box; otherwise, false. The default value is false.

Example

[Visual Basic, C#, C++] The following example demonstrates the use of the ShowReadOnly property. This example displays the OpenFileDialog box with the ShowReadOnly property set to true. If the user clicks the option to open the file in read-only mode, the OpenFile method is used to open the file. Otherwise, the FileStream class is used to open the file in read/write mode.

[Visual Basic] 

    Private Function OpenFile() As FileStream

        ' Displays an OpenFileDialog and shows the read/only files.

        Dim DlgOpenFile As New OpenFileDialog()
        DlgOpenFile.ShowReadOnly = True
        Dim Fs As FileStream

        If DlgOpenFile.ShowDialog() = DialogResult.OK Then

            ' If ReadOnlyChecked is true, uses the OpenFile method to
            ' open the file with read/only access.

            If DlgOpenFile.ReadOnlyChecked = True Then

                Return DlgOpenFile.OpenFile()

                ' Otherwise, opens the file with read/write access.

            Else

                Dim Path As String = DlgOpenFile.FileName
                Return New FileStream(Path, System.IO.FileMode.Open, _
                        System.IO.FileAccess.ReadWrite)


            End If

        End If


    End Function


[C#] 
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;


}


[C++] 
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 dynamic_cast<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 0;
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

OpenFileDialog Class | OpenFileDialog Members | System.Windows.Forms Namespace | ReadOnlyChecked

Show: