driveinfo

Best way to detect dvd insertion in drive c#

萝らか妹 提交于 2019-12-04 19:26:34
I tried using WMI to detect new media insertion in Disk Drive using following code. But is there managed solution like using loop in background thread with DriveInfo.GetDrives? Which is best way to do this? I'm getting 'Disk is not in the drive please insert disk' dialog with abort, retry and continue button on other pc when i tried the following code? On may machine it works fine. private void DriveWatcher() { try { var wqlEventQuery = new WqlEventQuery { EventClassName = "__InstanceModificationEvent", WithinInterval = new TimeSpan(0, 0, 1), Condition = @"TargetInstance ISA 'Win32_LogicalDisk

How to get Drive Letter and Name (volume label)

我的梦境 提交于 2019-12-04 12:18:48
问题 I have a program that tells me all the hard disks/ usb's, but it only tells me the drive letter not the name. Here is what I have: DriveInfo[] drives = DriveInfo.GetDrives(); Console.WriteLine("Detected Drives: "); for(int i = 0; i < drives.Count(); i++) { Console.WriteLine("Drive " + i + ": " + drives[i].Name); } return drives; and this prints: Drive 0: C:\ Drive 1: E:\ but I want the name such as Drive 0: C:\ Local disk Drive 1: E:\ Kingston USB how do I get this? 回答1: You are looking for

How to get Drive Letter and Name (volume label)

十年热恋 提交于 2019-12-03 07:42:20
I have a program that tells me all the hard disks/ usb's, but it only tells me the drive letter not the name. Here is what I have: DriveInfo[] drives = DriveInfo.GetDrives(); Console.WriteLine("Detected Drives: "); for(int i = 0; i < drives.Count(); i++) { Console.WriteLine("Drive " + i + ": " + drives[i].Name); } return drives; and this prints: Drive 0: C:\ Drive 1: E:\ but I want the name such as Drive 0: C:\ Local disk Drive 1: E:\ Kingston USB how do I get this? You are looking for the VolumeLabel property: http://msdn.microsoft.com/en-us/library/system.io.driveinfo.volumelabel.aspx

DriveInfo.GetDrives() not returning mapped drives when run as administrator

孤人 提交于 2019-11-30 22:08:40
I'm creating a WPF app that among other things should check for the existence of several mapped drives. The code is straightforward: DriveInfo[] systemDrives = DriveInfo.GetDrives(); foreach (DriveInfo i in systemDrives) { if ((i.Name.Contains("V")) && (i.IsReady)) { result = true; break; } } The mapped drives are mapped fro all users. The code above works fine when run as a regular user, however is Visual Studio 2010 is run as administrator the GetDrives method only returns the Fixed drives and the DVD drive but not the mapped drives. The same happens if the executable is run as an

How to get the list of removable disk in c#?

﹥>﹥吖頭↗ 提交于 2019-11-30 17:14:36
I want to get the list of removable disk in c#. I want to skip the local drives. Because i want the user to save the file only in removable disk. Lloyd Powell You will need to reference System.IO for this method. var driveList = DriveInfo.GetDrives(); foreach (DriveInfo drive in driveList) { if (drive .DriveType == DriveType.Removable) { //Add to RemovableDrive list or whatever activity you want } } Or for the LINQ fans: var driveList = DriveInfo.GetDrives().Where(d => d.DriveType == DriveType.Removable); Added As for the Saving part, as far as I know I don't think you can restrict where the

How to get the list of removable disk in c#?

孤街浪徒 提交于 2019-11-30 01:22:07
问题 I want to get the list of removable disk in c#. I want to skip the local drives. Because i want the user to save the file only in removable disk. 回答1: You will need to reference System.IO for this method. var driveList = DriveInfo.GetDrives(); foreach (DriveInfo drive in driveList) { if (drive .DriveType == DriveType.Removable) { //Add to RemovableDrive list or whatever activity you want } } Or for the LINQ fans: var driveList = DriveInfo.GetDrives().Where(d => d.DriveType == DriveType

How to correctly convert filesize in bytes into mega or gigabytes?

拟墨画扇 提交于 2019-11-29 03:03:32
I'm using the DriveInfo class in my C# project to retrieve the available bytes on given drives. How to I correctly convert this number into Mega- or Gigabytes? Dividing by 1024 will not do the job I guess. The results always differ from those shown in the Windows-Explorer. Adam Davis 1024 is correct for usage in programs. The reason you may be having differences is likely due to differences in what driveinfo reports as "available space" and what windows considers available space. Note that only drive manufacturers use 1,000. Within windows and most programs the correct scaling is 1024. Also,

.Net DriveInfo() with UNC paths?

我怕爱的太早我们不能终老 提交于 2019-11-28 08:49:56
问题 Good morning, is there a way to get a DriveInfo instance for UNC paths (e.g. "\fors343a.ww123.somedomain.net\folder\1\") because for example... var driveInfo = new System.IO.DriveInfo(drive); ... throws an ArgumentException ("Object must be a root directory (\"C:\\") or a drive letter (\"C\").") when using that UNC path above. What would I use in order to retrieve information about that or e.g. how would I check whether a given folder resides on a local drive or an unc path? 回答1: The Remarks

Mapped network drives cannot be listed in C#

不想你离开。 提交于 2019-11-28 00:31:52
问题 I am trying to list all local drives in my application, and DriveInfo.GetDrives give back the local drive letters, and I need the mapped drives too. Currently I have: C:, D:, and G: (HDD), E: and F: (CD), and S: and Z: (mapped network drives). (Yes, they are all visible in Windows Explorer, and in Total Commander too.) But only C, D, E, F, G are retrieved programmatically. I also tried Environment.GetLogicalDrives() , GetLogicalDriveStrings (pInvoke) , FindFirstVolume and FindNextVolumen

How to correctly convert filesize in bytes into mega or gigabytes?

末鹿安然 提交于 2019-11-27 17:20:02
问题 I'm using the DriveInfo class in my C# project to retrieve the available bytes on given drives. How to I correctly convert this number into Mega- or Gigabytes? Dividing by 1024 will not do the job I guess. The results always differ from those shown in the Windows-Explorer. 回答1: 1024 is correct for usage in programs. The reason you may be having differences is likely due to differences in what driveinfo reports as "available space" and what windows considers available space. Note that only