You can achieve this using the IMAPI v2 API.
Once you have the correct references within your .NET project, along with the various enums that are defined within that API (and there's quite a few of them!), the code is relatively straightforward. Something like (pseudo-code):
IDiscRecorder2 discRecorder = (IDiscRecorder2)[*cd/dvd drive*];
discFormatData.Recorder = discRecorder;
IMAPI_MEDIA_PHYSICAL_TYPE mediaType = discFormatData.CurrentPhysicalMediaType;
string mediaTypeString = GetMediaTypeString(mediaType);
where:
IMAPI_MEDIA_PHYSICAL_TYPE is an enum such like:
public enum IMAPI_MEDIA_PHYSICAL_TYPE
{
IMAPI_MEDIA_TYPE_UNKNOWN = 0,
IMAPI_MEDIA_TYPE_CDROM = 1,
IMAPI_MEDIA_TYPE_CDR = 2,
IMAPI_MEDIA_TYPE_CDRW = 3,
IMAPI_MEDIA_TYPE_DVDROM = 4,
IMAPI_MEDIA_TYPE_DVDRAM = 5,
[not the complete enum...snipped for brevity!]
}
and the "GetMediaTypeString" function simply gives a friendly string
representation of the enum name.
There's a good article and sample project on the CodeProject website that demonstrates this fairly comprehensively:
Burning and Erasing CD/DVD/Blu-ray Media with C# and IMAPI2
That project contains much more than just detecting the media type (hence the title!), but does contain code to effectively detect the media type prior to burning/erasing the media.
From the article:
Determining Media Type
To determine the media type and available space on the hard drive, you create a MsftDiscFormat2Data object and set the current recorder in the Recorder property. You can then get the media type from the IDiscFormat2Data CurrentPhysicalMediaType property.
Once you have the media type, create a MsftFileSystemImage object and call the ChooseImageDefaultsForMediaType method with the media type.