视频图像处理系列索引 || Arcgis/Engine/Server开发索引 || Web Map Gis开发索引 || jquery表格组件 JQGrid索引
WPF MVVM模式开发实现简明教程索引 || ArcGIS Runtime WPF(.net C#)开发简明教程索引

C# 获取磁盘剩余空间

drive.TotalFreeSpace单位为bit,根据需要除以1024
drive同时可以可以获取磁盘分区容量等
//单位MB
public static long GetHardDiskSpace(string str_HardDiskName)
{
long totalSize = 0;
str_HardDiskName = str_HardDiskName + ":\\";
System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
foreach (System.IO.DriveInfo drive in drives)
{
if (drive.Name == str_HardDiskName)
{
totalSize = drive.TotalFreeSpace / (1024 * 1024);
}
}
return totalSize;
}

  

调用方法:

string AppPath = Application.StartupPath.ToString();
string volume = AppPath.Substring(0, AppPath.IndexOf(':'));
long freespace = GetHardDiskSpace(volume);

  

posted @ 2016-09-14 10:31  jhlong  阅读(8667)  评论(0编辑  收藏  举报
海龙的博客 jhlong@cnblogs 版权所有© 转载请注明链接.有用请推荐一下
代码全部经过本人测试,但不保证复制粘贴就正常运行,更不保证能解决你的问题,请结合前后代码及描述理解后修改和使用