0

I want to get capacity of the disc in my Windows Phone 8.1 RT project.

I have learned that I need to use this function (p-invoking GetFileInformationByHandleEx) for this.

But I could not find any examples for use. Can someone help me by an example?

I tried following:

1.

private async Task<UInt64> GetCapacity(StorageFolder folder)
        {
            var retrivedProperties = await folder.Properties.RetrievePropertiesAsync(new string[] { "System.Capacity" });
            return (UInt64)retrivedProperties["System.Capacity"];
        }

2.

[DllImport("api-ms-win-core-file-l1-2-0.dll", CharSet = CharSet.Unicode, EntryPoint ="GetDiskFreeSpaceEx", SetLastError = true)]
        static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
                                      out ulong lpFreeBytesAvailable,
                                      out ulong lpTotalNumberOfBytes,
                                      out ulong lpTotalNumberOfFreeBytes);
                                      ulong GetDiskSize(string volumeName)
        {
            ulong avail;
            ulong total;
            ulong totalFree;
            GetDiskFreeSpaceEx(volumeName, out avail, out total, out totalFree);
            return total;
            // return others as desired
        }

I did not get result.

  • Possible duplicate of [How I can find out the avaible free space in a universal Windows Phone 8.1 App](http://stackoverflow.com/questions/23445993/how-i-can-find-out-the-avaible-free-space-in-a-universal-windows-phone-8-1-app) – Jamie Rees Jun 27 '16 at 14:14
  • I've seen this issue. I don't want to get FreeSpace. I want to get capacity of the disc. –  Jun 27 '16 at 14:19

1 Answers1

1

It is not possible because of the sandboxing.

We can get the free memory space about our Windows Phone, but it is not possible to get the full memory space, because our application can only access the memory of its isolated storage.

source

Also, there is no reference about a System.FullSpace or whatver on the MSDN.

By the way, a quick search around "p-invoking GetFileInformationByHandleEx" didn't yield any reference. I found the opposite.

aloisdg
  • 22,270
  • 6
  • 85
  • 105
  • I saw a reference that named **System.Capacity**. I tried using the **[following](https://gist.github.com/anonymous/370c1b1e0c644b39e96325a5c1db58d4)** but returns incorrect values. There are follow sentence in the answer of **[this](https://social.msdn.microsoft.com/Forums/en-US/56a017f7-c448-49f5-90cd-f04c04be0d42/winrt-how-to-get-the-total-disk-space-or-used-space)** question: ".. for those volumes you may be able to get some useful information by p-invoking GetFileInformationByHandleEx" If I understood correctly, can I get the total disk capacity with this function? –  Jun 27 '16 at 21:30
  • You said that not possible. But I saw many applications used this feature in the Windows Store. See. (iCleaner, Storage Cleaner Pro ... ) So how is this possible? There must be a way. –  Jun 28 '16 at 09:13
  • Are you sure they are WP 8.1 app? Not UWP or WP7app port to WP8.1? Why not a XNA app or whatever. What I am quoting is the fact that it is not possible and why for WP8.1 (also called WinPRT app). – aloisdg Jun 28 '16 at 14:44
  • Also, feel free to contact each dev of those apps and ask them how they did. – aloisdg Jun 28 '16 at 14:45