View Disk info on your web page

This is a very simple C# code snippet which allows you to display the Hard Disk info such as Total disk storage and Free Disk space on your machine. I found this intersting since it reveals a bit of local machine’s info through a browser.

Here goes the code.

using System.Management;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ManagementObject disk = new ManagementObject(“win32_logicaldisk.deviceid=\”c:\””);
disk.Get();
Response.Write(“Logical Disk Space = ” + disk[“Size”] + “bytes. “);
Response.Write(“Free space on C:\\ is ” + disk[“FreeSpace”] + ” bytes. “);
}
}

As you can see a Management object is created specifying the System Drive. You can access to its properties by the index of the Management Object. ex:- disk[“Size”] will give you the Total size of the drive.

Enjoy!!!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s