Click here to Skip to main content
15,885,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get the free disk space of a remote machine using c#? I am doing so via windows application in c#.

I am able to get the disk space of my system with below code

C#
//Check whether the Drive Fetched from App.Config exists in the system
      if (Environment.SystemDirectory.Contains(DBDriveName) == true)
      {
       //Fetch the Drive Name exists with that in the App.Config and see there is enough space to create DB Back Up
       foreach (DriveInfo drivename in DriveInfo.GetDrives())
       {

               //Fetching the free space of the drive from App.Config if existing and  obtaining the same in MB
               if (drivename.IsReady && drivename.Name == DBDriveName)
               {
                   TotalDiskFreeSpace = drivename.TotalFreeSpace / (1024 * 1024);
               }
        }



   }
   else
   {

       //Pass the msg if drive is not exisiting fetched from App.Config
       DbBackUpStatus = "Drive doesn't Exist";

   }
Posted

GetDiskFreeSpaceEx seems like your best bet.

/ravi
 
Share this answer
 
Hello,

You could use the same code above to get the free space of a mapped drive; however, sharing the root folder would not be recommended for obvious reasons. if you had a shared folder i believe the above code would only show you the quota set for that volume and not the entire drive.

Cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900