c#得到局域网共享剩余空间
[DllImport("kernel32.dll")]
private static extern bool GetDiskFreeSpaceEx(
string lpDirectoryName, out ulong lpFreeBytesAvailable, out ulong lpTotalNumberOfBytes, out ulong lpTotalNumberOfFreeBytes);
/// <summary>
/// 取得磁盘剩余空间
/// </summary>
/// <param name="driveDirectoryName">驱动器名</param>
/// <returns>剩余空间</returns>
private ulong GetFreeSpace(string driveDirectoryName)
{
ulong freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes;
GetDiskFreeSpaceEx(driveDirectoryName, out freeBytesAvailable, out totalNumberOfBytes, out totalNumberOfFreeBytes);
return freeBytesAvailable;
}
private static extern bool GetDiskFreeSpaceEx(
string lpDirectoryName, out ulong lpFreeBytesAvailable, out ulong lpTotalNumberOfBytes, out ulong lpTotalNumberOfFreeBytes);
/// <summary>
/// 取得磁盘剩余空间
/// </summary>
/// <param name="driveDirectoryName">驱动器名</param>
/// <returns>剩余空间</returns>
private ulong GetFreeSpace(string driveDirectoryName)
{
ulong freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes;
GetDiskFreeSpaceEx(driveDirectoryName, out freeBytesAvailable, out totalNumberOfBytes, out totalNumberOfFreeBytes);
return freeBytesAvailable;
}
ulong u = GetFreeSpace(@"\\10.222.1.1\shares");
MessageBox.Show(u.ToString());
网上找了下只能用API得到剩余空间大小, DriveInfo类只支持本地驱动器, 不支持UNC路径.