查詢硬碟剩餘空間(using WinAPI)

using System.Runtime.InteropServices;
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
    out ulong lpFreeBytesAvailable,
    out ulong lpTotalNumberOfBytes,
    out ulong lpTotalNumberOfFreeBytes);

string drive = "D:\\";      // 要查詢剩餘空間的磁碟
ulong FreeBytesAvailable;
ulong TotalNumberOfBytes;
ulong TotalNumberOfFreeBytes;
bool success = GetDiskFreeSpaceEx(drive, out FreeBytesAvailable, out TotalNumberOfBytes, out TotalNumberOfFreeBytes);

if (!success)    throw new System.ComponentModel.Win32Exception();

double free_kilobytes = (double)(Int64)TotalNumberOfFreeBytes / 1024.0;
double free_megabytes = free_kilobytes / 1024.0;
double free_gigabytes = free_megabytes / 1024.0;

//取得Server IP
System.Net.IPAddress sever_ip = new System.Net.IPAddress(System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList[0].Address);
Response.Write(sever_ip.ToString() + " 剩餘 " + free_gigabytes.ToString("0.00") + " GB");

[C#]查詢硬碟剩餘空間(透過WinAPI) - .NET菜鳥自救會- 點部落
C# 如何取得本機(Server)的IP @ R~福氣拉! :: 隨意窩 Xuite日誌