OpenFileDialog.ReadOnlyChecked Property

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

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public:
property bool ReadOnlyChecked {
	bool get ();
	void set (bool value);
}
/** @property */
public boolean get_ReadOnlyChecked ()

/** @property */
public void set_ReadOnlyChecked (boolean value)

public function get ReadOnlyChecked () : boolean

public function set ReadOnlyChecked (value : boolean)

Property Value

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

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.

The following code 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.

private:
   FileStream^ OpenFile()
   {
      // Displays an OpenFileDialog and shows the read/only files.
      OpenFileDialog^ dlgOpenFile = gcnew 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 gcnew FileStream( path,System::IO::FileMode::Open,System::IO::FileAccess::ReadWrite );
         }
      }

      return nullptr;
   }

private FileStream OpenFile()
{
    // Displays an OpenFileDialog and shows the read/only files.
    OpenFileDialog dlgOpenFile = new OpenFileDialog();
    dlgOpenFile.set_ShowReadOnly(true);
    if (dlgOpenFile.ShowDialog().Equals(get_DialogResult().OK)) {
        // If ReadOnlyChecked is true, uses the OpenFile method to
        // open the file with read/only access.
        if (dlgOpenFile.get_ReadOnlyChecked() == true) {
            return (FileStream)dlgOpenFile.OpenFile();
        }
        // Otherwise, opens the file with read/write access.
        else {
            String path = dlgOpenFile.get_FileName();
            return new FileStream(path, System.IO.FileMode.Open,
                System.IO.FileAccess.ReadWrite);
        }
    }
    return null;
} //OpenFile 

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show: