Programmatically determine Total Free Space available on your Hard Drive

using System.IO;

public partial class DescSpace : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int i = 0;
        foreach (DriveInfo drive in DriveInfo.GetDrives())
        {
            try
            {
                Label lblDriveName = new Label();
                Label lblDriveSize = new Label();
                lblDriveName.ID = "lblDriveName" + i.ToString();
                lblDriveSize.ID = "lblDriveSize"+i.ToString();
                lblDriveName.Text = "Drive Name is :" + drive.RootDirectory.ToString();
                lblDriveSize.Text="Drive Having Size in MB :"+Convert.ToString((drive.AvailableFreeSpace / 1024) / 1024);
                PlaceHolder1.Controls.Add(lblDriveName);
                PlaceHolder1.Controls.Add(lblDriveSize);
                i = i + 1;
            }
            catch (IOException io)
            {
                
            }
            catch (Exception ex)
            {
              
            }
        }
       
    }

0 comments: