Possible Duplicate:
how to get disk information by using c#?
Given each of the inputs below, I'd like to get free space on that location. Something like
long GetFreeSpace(string path)
Inputs:
c:
c:\
c:\temp
\\server
\\server\C\storage
Possible Duplicate:
how to get disk information by using c#?
Given each of the inputs below, I'd like to get free space on that location. Something like
long GetFreeSpace(string path)
Inputs:
c:
c:\
c:\temp
\\server
\\server\C\storage
DriveInfo will help you with some of those (but it doesn't work with UNC paths), but really I think you will need to use GetDiskFreeSpaceEx. You can probably achieve some functionality with WMI. GetDiskFreeSpaceEx looks like your best bet.
Chances are you will probably have to clean up your paths to get it to work properly.
untested:
using System;
using System.Management;
ManagementObject disk = new
ManagementObject("win32_logicaldisk.deviceid="c:"");
disk.Get();
Console.WriteLine("Logical Disk Size = " + disk["Size"] + " bytes");
Console.WriteLine("Logical Disk FreeSpace = " + disk["FreeSpace"] + "
bytes");
Btw what is the outcome of free diskspace on c:\temp ? you will get the space free of c:\