public override void SetLength(long value)
        {
            container.PreCheck();
            // don't worry about quota if we can't write to the stream,
            // the base class will throw the expected NotSupportedException
            if (!base.CanWrite)
            {
                return;
            }

            // will that request put us in a position to grow *or shrink* the file ?
            // note: this can be negative, e.g. calling SetLength(0), so we can't call EnsureQuotaLimits directly
            if (!IsolatedStorage.CanExtend(value - Length))
            {
                throw new IsolatedStorageException("Requested size is larger than remaining quota allowance.");
            }

            base.SetLength(value);
        }
        private void EnsureQuotaLimits(long request)
        {
            // don't worry about quota if we can't write to the stream,
            // the base class will throw the expected NotSupportedException
            if (!base.CanWrite)
            {
                return;
            }

            // will that request put us in a position to grow the file ?
            long grow = Position + request - Length;

            if (grow < 0)
            {
                return;
            }

            if (!IsolatedStorage.CanExtend(grow))
            {
                throw new IsolatedStorageException("Requested size is larger than remaining quota allowance.");
            }
        }