小编CB *_*dav的帖子

WinRT中的磁盘空间在Windows 8中使用C#

我有两个解决方案,但两个对我都没用.

解决方案1:kernel32.dll(其工作代码)

注意:但我不想在我的应用程序中导入任何dll.b/c市场提交的问题.

[DllImport("kernel32.dll", SetLastError = true)]
static extern bool GetDiskFreeSpaceEx(
    string lpDirectoryName,
    out ulong lpFreeBytesAvailable,
    out ulong lpTotalNumberOfBytes,
    out ulong lpTotalNumberOfFreeBytes);


static void TestDiskSpace()
{
    IStorageFolder appFolder = ApplicationData.Current.LocalFolder;
    ulong a, b, c;
    if(GetDiskFreeSpaceEx(appFolder.Path, out a, out b, out c))
        Debug.WriteLine(string.Format("{0} bytes free", a));
}
Run Code Online (Sandbox Code Playgroud)

解决方案2:使用DriveInfo类(WinRT不工作代码)

注意:WinRT开发中缺少名称空间.WinRT for Windows 8开发不支持此类.

DriveInfo[] allDrives = DriveInfo.GetDrives();

    foreach (DriveInfo d in allDrives)
    {
        Console.WriteLine("Drive {0}", d.Name);
        Console.WriteLine("  File type: {0}", d.DriveType);
        if (d.IsReady == true)
        {
            Console.WriteLine("  Volume label: {0}", d.VolumeLabel);
            Console.WriteLine(" …
Run Code Online (Sandbox Code Playgroud)

c# windows-8 windows-runtime

4
推荐指数
2
解决办法
1830
查看次数

标签 统计

c# ×1

windows-8 ×1

windows-runtime ×1