This documentation is archived and is not being maintained.

OpenFileDialog.ReadOnlyChecked Property

Gets or sets a value indicating whether the read-only check box is selected.

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

Property Value

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

Remarks

The ReadOnlyChecked state does not affect the read/write mode that OpenFileDialog.OpenFile uses to open a file selected in the dialog box. OpenFile will always open the file in read-only mode.

The ShowReadOnly property must be set before in order for the read-only check box to appear in the dialog box.

Example

[Visual Basic, C#, C++] The following example demonstrates the use of the ReadOnlyChecked 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 ReadOnlyChecked property evaluates to true, and 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 | ShowReadOnly

Show: