Hi all,
Here is I'm going to getting disk space and free space using WMI. For that we must add refference System.Management.dll. The below is coding ...check it out...
using System.Management;
RadioButton rdDrives;
private void Form1_Load(object sender, EventArgs e)
{
int i = 10;
foreach (string drives in Environment.GetLogicalDrives())
{
rdDrives = new RadioButton();
rdDrives.Text = drives;
rdDrives.Top = i+20;
this.Controls.Add(rdDrives);
Application.DoEvents();
i = i + 40;
}
}
private void btnGetDiskSpace_Click(object sender, EventArgs e)
{
string drive = "";
RadioButton rd;
//Control[] control = this.Controls.Find("RadioButton", false);
for (int j = 0; j < rd =" (RadioButton)this.Controls[j];" drive =" rd.Text;" drive =" drive.Substring(0,">
private void getSize(string drive)
{
ManagementObject diskSize = new ManagementObject("win32_logicaldisk.deviceid=\"" + drive + ":\"");
diskSize.Get();
lblSize.Text = "Disk Space in " + drive + " is :" + diskSize["Size"] + " bytes";
lblFreeSpace.Text = "Free space in " +drive +" is :" + diskSize["FreeSpace"] + " bytes";
}
OutPut:
That's it..
...S.VinothkumaR.
1 comment:
i use "ManagementObject diskSize = new ManagementObject("win32_logicaldisk.deviceid=\"" + drive + ":\"");
diskSize.Get();
lblFreeSpace.Text = "Free space in " +drive +" is :" + diskSize["FreeSpace"] + " bytes"; "
this part only i cant able to get free space in that line"ManagementObject diskSize = new ManagementObject("win32_logicaldisk.deviceid=\"" + drive + ":\"");" it throughs exception.
im using VS 2005
Post a Comment