jv42
jv42

Reputation: 8593

Is there a way to get available disk space in Silverlight?

I'm currently trying to determine the available disk space from my Silverlight application.

My app can download a lot of data (video files) and obviously, this can fail if the disk space isn't there. I know I can catch exceptions on writes, but that will not lead to a very user-friendly experience, because the information will come too late and cause useless waits.

In regular .NET, I would be using DriveInfo (see How do I retrieve disk information in C#? for an example), but that class isn't present as of Silverlight 5, even in elevated trust mode.

So, is there a way to determine the available space on a drive in Silverlight?


Update:

Upvotes: 3

Views: 622

Answers (2)

jv42
jv42

Reputation: 8593

I'm adding my answer here to sum up my discoveries:

TL/DR: there is no easy way to get available disk space in Silverlight 5 that is cross-platform (Windows/Mac OS).

  • You can't get available disk space with standard Silverlight calls. DriveInfo is missing from Silverlight 5, elevated privileges don't come into account here.
  • Quota is useless for that kind of issue, it doesn't take into account available disk space.
  • There are workarounds for Windows only, requiring elevated trust, using P/Invoke into Win32.
  • For a detailed support of filesystem, see this article: http://www.codeproject.com/KB/silverlight/FileExplorerInSilverlight.aspx
  • Fall-back is to check for exceptions when writing files and present the user with a message at the time of writing. People have also suggested pre-writing the file when the download start to ensure sufficient disk space.

Upvotes: 0

Joseph Le Brech
Joseph Le Brech

Reputation: 6653

There has been filebrowser demos out there written in Silverlight but they would run with elevated trust.

That means that you would have to make the user immediately suspicious of your application when they first run it.

It's probably a better user experience to just have a well worded error message for when the user runs out of space.

Another option would be to try an increase the isolated storage quota by the size of the biggest video available.

http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile.increasequotato(v=vs.95).aspx

Then when that fails just let the user know that no more space can be allocated for the app had that he may need to delete older videos.

Upvotes: 1

Related Questions