2 out of 3 rated this helpful - Rate this topic

IsolatedStorageFile.IncreaseQuotaTo Method

Enables an application to explicitly request a larger quota size, in bytes.

Namespace:  System.IO.IsolatedStorage
Assembly:  mscorlib (in mscorlib.dll)
[SecuritySafeCriticalAttribute]
public bool IncreaseQuotaTo(
	long newQuotaSize
)

Parameters

newQuotaSize
Type: System.Int64
The requested size, in bytes.

Return Value

Type: System.Boolean
true if the new quota is accepted by the user, otherwise, false.
Exception Condition
IsolatedStorageException

The isolated store has been removed.

-or-

Isolated storage is disabled.

ArgumentOutOfRangeException

newQuotaSize is less than zero

-or-

newQuotaSize is less than or equal to the value of the Quota property.

ObjectDisposedException

The isolated store has been disposed.

ArgumentException

newQuotaSize is invalid.

An application shares its quota with all other applications that are hosted on the same domain (Web site). The initial quota is 1 MB to be shared by all of the domain's applications.

The new quota size must not be less than the current quota. Only quota increases are allowed.

To increase the quota, you must call this method from a user-initiated event, such as in an event handler for a button-click event. When you call the IncreaseQuotaTo method, the common language runtime in Silverlight presents a dialog box for the user to approve the request. If the user declines the request, this method returns false and the quota remains the same size.

The following example requests an increase in the quota size. This example is part of a larger example provided for IsolatedStorageFile class.


// Assumes an event handler for the MouseLeftbuttonUp
// event is defined for a control named 'IncreaseQuota'
// In the control's XAML: MouseLeftButtonUp="IncreaseQuota_OnLeftMouseButtonUp"

// User first selects UI to increase the quota.
public void IncreaseQuota_OnClick(object sender, MouseEventArgs e)
{

    // Obtain an isolated store for an application.
    try
    {
        using (var store = IsolatedStorageFile.GetUserStoreForApplication())
        {
            // Request 5MB more space in bytes.
            Int64 spaceToAdd = 5242880;
            Int64 curAvail = store.AvailableFreeSpace;

            // If available space is less than
            // what is requested, try to increase.
            if (curAvail < spaceToAdd)
            {

                // Request more quota space.
                if (!store.IncreaseQuotaTo(store.Quota + spaceToAdd))
                {
                    // The user clicked NO to the
                    // host's prompt to approve the quota increase.
                }
                else
                {
                    // The user clicked YES to the
                    // host's prompt to approve the quota increase.
                }
            }
        }
    }

    catch (IsolatedStorageException)
    {
        // TODO: Handle that store could not be accessed.

    }
}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Must call this method from a user-initiated event

I must second that this is a ridiculous limitation for several reasons. It is pointless because as mentioned above, the user will be prompted with a modal dialog anyway. There is no need to require user interaction in the first place. Secondly, the implementation of this is actually buggy. I don't know what the actual logic, but it seems that the dialog will only display if no other code has been executed before the IncreaseQuotaTo call has been made. So for example, my code was working fine, but when I put some inline database code before the IncreaseQuotaTo call in private void CreateDatabase_Click(object sender, RoutedEventArgs e), the method returns false without telling me why it didn't allow the box to popup.

But also, this makes for very sloppy coding. I always make it a point to move logic outside the event handlers. Now, I'm being forced to put logic inside the event handlers. I can't even move the logic to helper methods. This is massive overkill.

 Imagine if a Windows application always had to put its code in a button click event handler when trying to access files that require administrative access.

AccessViolation
If your application throws an AccessViolation exception, see http://connect.microsoft.com/VisualStudio/feedback/details/675183/silverlight-isolated-storage-space-increase-throws-an-access-violation-exception-crashes-the-browser for details.
What's the point of this restriction?
"To increase the quota, you must call this method from a user-initiated event, such as in an event handler for a button-click event." $0$0 $0 $0Why???$0 $0$0 $0 $0I was writing a caching mechanism and I need to ask for quota increase if the cache is too big (like 2M).$0 $0Now I have to create and open a modal window with a button that calls another window (the actual increase quota window) to make it work.$0 $0 $0$0 $0 $0If we already have a modal window asking for user permission, what's the point of this restriction?$0