Skip to main content

Microsoft Silverlight

Unanswered Question OpenFileDialog causes IsolatedStorageFile.IncreaseQuotaTo to failRSS Feed

(0)

NinetiesGuy
NinetiesGuy

Member

Member

12 points

3 Posts

OpenFileDialog causes IsolatedStorageFile.IncreaseQuotaTo to fail

Hey guys,

I'm using Silverlight 2 beta 2... 

After a button click, if you show a file dialog, a call to increase the isolated storage quota will fail without showing the user dialog. 

Here's the process I'm trying to get to work:  When the user clicks the button, show the file dialog, calculate quota increase based on the selected files, increase quota if necessary, and store files.

If the call to IsolatedStorageFile.IncreaseQuotaTo is placed before the file dialog, it works as expected. But that isn't an option because I need to calculate the size needed based on the file dialog result.

Here's code to reproduce:

private void button_Click(object sender, RoutedEventArgs e)
{
   using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
   {
      //this shows increase request dialog
      isolatedStorageFile.IncreaseQuotaTo(isolatedStorageFile.Quota * 2);
            
      OpenFileDialog openFileDialog = new OpenFileDialog();
            
      if (openFileDialog.ShowDialog() == true)
      {
         //this doesn't show increase dialog, returns false automatically
         isolatedStorageFile.IncreaseQuotaTo(isolatedStorageFile.Quota * 2);
      }
   }
}

Thanks,

Chris 

lilach
lilach

Member

Member

4 points

6 Posts

Re: OpenFileDialog causes IsolatedStorageFile.IncreaseQuotaTo to fail

Hi Chris,

we are now having the same problem, Did you get any information about this?

thanks,

Lilach

kwatts
kwatts

Contributor

Contributor

2129 points

436 Posts

Re: OpenFileDialog causes IsolatedStorageFile.IncreaseQuotaTo to fail

It turns out that the default limit for isolated storage is now 100 KB, which is down from 1 MB in Silverlight 1.0.  This article has more details:

http://silverlightuk.blogspot.com/2008/02/isolated-storage-in-silverlight-2.html

The good news is this limit can be increased, but it's something that needs to be done on the user's end.  I hope that this helps!

-Ken 


http://kenwatts.blogspot.com/


Please select "Mark as Answer" for posts that are helpful. Thanks!

NinetiesGuy
NinetiesGuy

Member

Member

12 points

3 Posts

Re: OpenFileDialog causes IsolatedStorageFile.IncreaseQuotaTo to fail

Lilach: No, still haven't found a solution. Our best workaround is to just pick some arbitrary large number and hope that's big enough. Annoying because I have to error-check everything I do after the dialog closes to ensure there is enough space at that moment. If it worked correctly, I could allocate enough space early in the process and not have to worry about it anymore.

 kwatts: The problem isn't increasing the storage quota. The problem is increasing it after the OpenFileDialog is shown. IncreaseQuotaTo returns false without prompting the user. So if you're dealing with the file system at all, there's no way to know how much space you need.

Thanks,

Chris

kwatts
kwatts

Contributor

Contributor

2129 points

436 Posts

Re: OpenFileDialog causes IsolatedStorageFile.IncreaseQuotaTo to fail

NinetiesGuy:

kwatts: The problem isn't increasing the storage quota. The problem is increasing it after the OpenFileDialog is shown. IncreaseQuotaTo returns false without prompting the user. So if you're dealing with the file system at all, there's no way to know how much space you need.

My point is you're not going to be able to  increase the quota beyond 100K in code.  The end-user will have to do this manually.  I'm guessing there are security concerns here.

-Ken 


http://kenwatts.blogspot.com/


Please select "Mark as Answer" for posts that are helpful. Thanks!

lilach
lilach

Member

Member

4 points

6 Posts

Re: OpenFileDialog causes IsolatedStorageFile.IncreaseQuotaTo to fail

our problem is only that the IncreaseQuotaTo returns false without prompting the user. is there a chance that the storage quota was increased even though it didn't prompt the user?

we are asking for 200M from the user. 100K will certanly not be enough.

does anyone know the reason the window fails to open?

thanks,

Lilach

ahura mazda
ahura mazda

Member

Member

40 points

5 Posts

Re: OpenFileDialog causes IsolatedStorageFile.IncreaseQuotaTo to fail

I'm having the same issue but with the RTW version.

Using Reflector, I see that the method IncreaseQuotaTo() internally calls a security method that always returns false, which looks like it eventually will cause IncreaseQuotaTo to fail.

Did a bit more research and the call to IncreaseQuotaTo() must be called from an event handler (it states so in the Silverlight SDK). I'm assuming that OpenFileDialog.ShowDialog() probably resets some internal checks and anycalls after to IncreaseQuotaTo() will fail silently.

Did even more look ups and found this:
http://www.wilcob.com/Wilco/View.aspx?NewsID=211 

 

martinording
martinor...

Member

Member

5 points

15 Posts

Microsoft, this really needs to be fixed

 A typical usage patter for OpenFileDialog and IncreaseQuotaTo is this:

bool save = false;
OpenFileDialog dialog = new OpenFileDialog();
if (dialog.ShowDialog())
{
    using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
    {
        if (iso.AvailableFreeSpace < dialog.File.Length)
        {
            save = iso.IncreaseQuotaTo(iso.Quota - iso.AvailableFreeSpace + dialog.File.Length);
        }
        else
            save = true;
    }
}
if (save)
{
    // ...
}

When IsolatedStorageFile.IncreaseQuotaTo gets called, it is always after a call to OpenFileDialog.ShowDialog.

You really need to allow IncreaseQuotaTo to be called after OpenFileDialog.ShowDialog. It is the only way to make Silverlight apps user friendly.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities