Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Win32
Hi, I have a CDROM drive which is ready (I think so, because I can open a disc using it without having any problem), but I tried getting its volume label and there was an exception saying "The device is not ready":
 
Here is my code:
DriveInfo cd = new DriveInfo("F"); //My CD ROM drive
MessageBox.Show(cd.VolumeLabel)
How can I get its volume label?
 
Your help would be highly appreciated! Thanks!
Posted 17-Sep-12 5:14am
supernorb2.5K
Edited 17-Sep-12 5:59am
v2
Comments
Alan N at 17-Sep-12 12:20pm
   
The volume label is associated with a disk. Is there one in the drive?
Wes Aday at 17-Sep-12 13:03pm
   
I think that you probably have the right answer here.
supernorb at 17-Sep-12 13:28pm
   
Thank you, why didn't you give your answer to my question?
Yeah, my drive didn't have any disk, and after inserting a one, it worked! Thanks again!
 
However, my CD Ejector became useless when it can't eject my CD Drive when the drive has a disk, I just tested when the drive didn't have a disk. I collected the code at StackOverFlow, well, it seems to be rather complicated, I used winmm.dll and it works well, but with CreateFile and dozens of other functions don't work!

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Check for cd.IsReady flag,if it is false the device is not actually ready and you can put the code to sleep and try again.If it is always false then there is a problem with the Drive.
  Permalink  
Comments
supernorb at 17-Sep-12 13:15pm
   
Of course, the cd.IsReady is false, but in fact there is not any problem with my drive, it is still working properly.
My want is how to get the VolumeLabel of a CD ROM drive, my approach using DriveInfo seems to be not feasible, Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Dnyaneshwar@Pune 604
1 thatraja 370
2 OriginalGriff 319
3 Sergey Alexandrovich Kryukov 243
4 Gihan Liyanage 194
0 OriginalGriff 737
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 505
3 Sergey Alexandrovich Kryukov 372
4 thatraja 370


Advertise | Privacy | Mobile
Web01 | 2.8.140902.1 | Last Updated 17 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100