Click here to Skip to main content
15,893,508 members
Home / Discussions / C#
   

C#

 
AnswerRe: The magic of TransactionScope Pin
Pete O'Hanlon12-Jul-07 2:49
mvePete O'Hanlon12-Jul-07 2:49 
GeneralRe: The magic of TransactionScope Pin
Le centriste12-Jul-07 2:53
Le centriste12-Jul-07 2:53 
AnswerRe: The magic of TransactionScope Pin
Judah Gabriel Himango12-Jul-07 5:05
sponsorJudah Gabriel Himango12-Jul-07 5:05 
Questionhow to close child form on the click event of toolstrip button Pin
monuSaini12-Jul-07 0:44
monuSaini12-Jul-07 0:44 
AnswerRe: how to close child form on the click event of toolstrip button Pin
Bekjong12-Jul-07 2:04
Bekjong12-Jul-07 2:04 
QuestionC# USB Detection [modified] Pin
donovan.solms12-Jul-07 0:43
donovan.solms12-Jul-07 0:43 
AnswerRe: C# USB Detection Pin
Giorgi Dalakishvili12-Jul-07 1:10
mentorGiorgi Dalakishvili12-Jul-07 1:10 
AnswerRe: C# USB Detection Pin
Martin#12-Jul-07 1:38
Martin#12-Jul-07 1:38 
Hello,

I'm using System.Management functionality for that!
//Insert
WqlEventQuery q_creation = new WqlEventQuery();
q_creation.EventClassName = "__InstanceCreationEvent";
q_creation.WithinInterval = new TimeSpan(0,0,2);    //How often do you want to check it? 2Sec.
q_creation.Condition = @"TargetInstance ISA 'Win32_DiskDriveToDiskPartition'";
mwe_creation = new ManagementEventWatcher(q_creation);
mwe_creation.EventArrived += new EventArrivedEventHandler(USBEventArrived_Creation);
mwe_creation.Start(); // Start listen for events
 
internal void USBEventArrived_Creation(object sender, EventArrivedEventArgs e) 
{
 
}
 
//Remove
WqlEventQuery q_deletion = new WqlEventQuery();
q_deletion.EventClassName = "__InstanceDeletionEvent";
q_deletion.WithinInterval = new TimeSpan(0,0,2);    //How often do you want to check it? 2Sec.
q_deletion.Condition = @"TargetInstance ISA 'Win32_DiskDriveToDiskPartition'  ";
mwe_deletion = new ManagementEventWatcher(q_deletion);
mwe_deletion.EventArrived += new EventArrivedEventHandler(USBEventArrived_Deletion);
mwe_deletion.Start(); // Start listen for events
 
internal void USBEventArrived_Deletion(object sender, EventArrivedEventArgs e) 
{
 
}


For checking the free and available space:
public void Hashtable GetFreeDriveSpace()
{
	Hashtable drivefreespace = new Hashtable();
	// Get the management class holding Logical Drive information
	ManagementClass mcDriveClass = new ManagementClass("Win32_LogicalDisk");
	// Enumerate all logical drives available
	ManagementObjectCollection mocDrives = mcDriveClass.GetInstances();
	foreach(ManagementObject moDrive in mocDrives)
	{
		/*
		Other values of DriveType property:
		0 Unknown 
		1 No Root Directory 
		2 Removable Disk 
		3 Local Disk 
		4 Network Drive 
		5 Compact Disc 
		6 RAM Disk 
		*/
		try
		{
			//if (int.Parse(moDrive.Properties["DriveType"].Value.ToString()) == 3) //You can check the drive type here
			//{
				// sDeviceId will hold the drive name eg "C:"
				String sDeviceId = moDrive.Properties["DeviceId"].Value.ToString();
				// dSize and dFree will hold the size of the drive and free space in bytes
				double dSize = double.Parse(moDrive.Properties["Size"].Value.ToString());
				double dFree = double.Parse(moDrive.Properties["FreeSpace"].Value.ToString()); //In Byte
			//}
		}
		catch
		{
		}
	}
	mocDrives.Dispose();
	mcDriveClass.Dispose();
}


Hope it helps!

All the best,

Martin

GeneralRe: C# USB Detection Pin
donovan.solms12-Jul-07 1:54
donovan.solms12-Jul-07 1:54 
QuestionHow to convert CSV file to XLS file using C# Programme Pin
liyakhat_shahid12-Jul-07 0:27
liyakhat_shahid12-Jul-07 0:27 
AnswerRe: How to convert CSV file to XLS file using C# Programme Pin
Bijesh12-Jul-07 1:06
Bijesh12-Jul-07 1:06 
GeneralRe: How to convert CSV file to XLS file using C# Programme Pin
liyakhat_shahid13-Jul-07 1:55
liyakhat_shahid13-Jul-07 1:55 
AnswerRe: How to convert CSV file to XLS file using C# Programme Pin
Jimmanuel12-Jul-07 1:15
Jimmanuel12-Jul-07 1:15 
AnswerRe: How to convert CSV file to XLS file using C# Programme Pin
martin_hughes12-Jul-07 2:30
martin_hughes12-Jul-07 2:30 
AnswerRe: How to convert CSV file to XLS file using C# Programme Pin
Pete O'Hanlon12-Jul-07 3:03
mvePete O'Hanlon12-Jul-07 3:03 
QuestionProblem with Cookies Enabled detection Pin
Adoremi11-Jul-07 23:10
Adoremi11-Jul-07 23:10 
AnswerRe: Problem with Cookies Enabled detection Pin
chandu_shar12-Jul-07 0:21
chandu_shar12-Jul-07 0:21 
Questiondisable all DataGridViewRowHeaderCell glyphs Pin
agent32711-Jul-07 22:37
agent32711-Jul-07 22:37 
QuestionProblems with configuring .Net hosted control Pin
drweb8611-Jul-07 22:24
drweb8611-Jul-07 22:24 
Questionradiobutton BeforeStateChange ? Pin
fracalifa11-Jul-07 22:20
fracalifa11-Jul-07 22:20 
AnswerRe: radiobutton BeforeStateChange ? Pin
Martin#11-Jul-07 22:32
Martin#11-Jul-07 22:32 
AnswerRe: radiobutton BeforeStateChange ? Pin
Luc Pattyn11-Jul-07 23:48
sitebuilderLuc Pattyn11-Jul-07 23:48 
GeneralRe: radiobutton BeforeStateChange ? Pin
Martin#12-Jul-07 0:05
Martin#12-Jul-07 0:05 
GeneralRe: radiobutton BeforeStateChange ? [modified] Pin
fracalifa12-Jul-07 0:32
fracalifa12-Jul-07 0:32 
GeneralRe: radiobutton BeforeStateChange ? Pin
Luc Pattyn12-Jul-07 0:36
sitebuilderLuc Pattyn12-Jul-07 0:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.