2012-01-25 20 views
1

準備錯誤我有方法,其檢索其是NTFS的可移動設備的信息:設備不是上DriveInfo.DriveFormat

private void getdriverinfo() 
    { 
     // get the usb flash driver 
     foreach (DriveInfo driveInfo in DriveInfo.GetDrives()) 
     { 
      if (driveInfo.DriveType == DriveType.Removable && driveInfo.DriveFormat.Equals("NTFS")) 
      { 
       comboBox1.Items.Add(driveInfo.Name); 
      } 
     } 
     if (comboBox1.Items.Count == 0) 
     { 
      MessageBox.Show("No Removable Device Found , please plug in the USB drive and make sure it is in NTFS format and retry", "No Device Found!", MessageBoxButtons.OK, MessageBoxIcon.Information); 
     } 
     else if (comboBox1.Items.Count == 1) 
     { 
      comboBox1.Text = comboBox1.Items[0].ToString(); 
     } 
     else 
     { 
      MessageBox.Show(comboBox1.Items.Count + " Removable Devices were found , please choose the device you want to protect"); 
     } 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     // get the usb flash driver 
     getdriverinfo();  
    } 

發生此錯誤:

System.IO.IOException:該設備未準備好。

在System.IO .__ Error.WinIOError(的Int32的errorCode,字符串maybeFullPath)

在System.IO .__ Error.WinIODriveError(字符串DRIVENAME,的Int32的errorCode)

在System.IO.DriveInfo.get_DriveFormat ()

在USB_Data_Protector.Form1.getdriverinfo()

這工作得很好我的筆記本電腦沒有任何錯誤。當它在虛擬PC或其他PC上運行時,會顯示此錯誤。

回答

5

在訪問DriveFormat之前可以檢查以下內容嗎? IsReady Property

driveInfo.IsReady 
+0

哇,它的工作,但爲什麼?也許是因爲它需要時間做好準備或做什麼? –

+1

添加了該屬性的相關鏈接 – chandmk

相關問題