Sponsored Ad

Thursday, January 13, 2011

How to Find Disk Size, Free Disk Space and Disk Space Occupied in System using C#

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.

How to Find Disk Size, Free Disk Space and Disk Space Occupied in System using C#

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

Sponsored Ad

Website Update

Followers