This C# code will help you to get the total space available in System and also let you know the free and occupied space. Let me know if you face any problem while implementing.
C# Code:
using System;
using System.Management;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
string strOccupiedSpace = "";
ManagementObject obj = new
ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
obj.Get();
Console.WriteLine("Logical Disk Size: (bytes) " + obj["Size"]);
Console.WriteLine("Logical Disk FreeSpace: (bytes) " + obj["FreeSpace"] );
strOccupiedSpace = Convert.ToString(Convert.ToDecimal(obj["Size"]) - Convert.ToDecimal(obj["FreeSpace"]));
Console.WriteLine("Logical Disk OccupiedSpace: (bytes) " + strOccupiedSpace );
Console.ReadLine();
}
}
}
0 comments:
Post a Comment