3

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:

  • I'm fine with requiring Elevated Priviledges for my application.
  • I'm also fine with Silverlight 5 only solutions.
  • I need something that works on both Windows and Mac OS, so PInvoke/COM interop is not an option.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

10 Comments

I'm OK with using elevated trust, I will clarify that in my question.
IsolatedStorage quota is (sadly) not related to real disk space available, you can request any quota you wish, it's just used to request permission from the user to write that amount.
you can do this forums.silverlight.net/t/146323.aspx/1 but it will be windows only. finding disk space will be windows only.
I would like to avoid COM interop, I need it to work on Mac too.
Isn't running out of disk space a very rare occurrence these days? I agree that you should just fail if you run into this problem, instead of always checking for it. Best case, do the check on Windows with pinvoke, and fail if you get an error on Mac
|
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.