Thursday, August 03, 2006

Check DriveInfo.IsReady Before Using DriveInfo Members

I noticed that calling various members of the DriveInfo class will cause an error if the drive is not ready; therefore, check the IsReady property to determine if the drive is ready accordingly.

foreach (DriveInfo drive in DriveInfo.GetDrives()) { if (drive.IsReady) this.txtStatus.Text += drive.Name + "; " + drive.DriveFormat + "\r\n"; }

Also, all types of optical drives have a DriveType enumeration of CDRom.