Isolation Storage Out of Browser Silverlight 4.0 Application for Fetching and Displaying Image and VideoFile



Description: In this Article I will describe using Isolations Storage; how to fetch and display video and image files using Isolation Storage in Silverlight.

Content: Silverlight uses Isolated Storage as a virtual file system to store data in a hidden folder on your machine. It breaks up the data into two separate sections: Section 1 contains administrative information such as disk quota and section 2 contains the actual data. Each Silverlight application is allocated its own portion of the storage with the current quota set to be 1 MB per application. It is the by default storage quota. So if the quota exceeds that then you have to programmatically increase the Isolation Storage Quota. That I will describe in this article Later. Reference - http://www.telerik.com/help/silverlight/consuming-data-isolated-storage.html

First create a new Silverlight Application with the name Isolation Media Element.

Isolation1.gif

Now create a UserControl Name DisplayVideo.xaml. Which I will integrate to the Mainpage.xaml.

In the main Page.xaml I have written the code for fetching and display the image file from Isolation Storage.

In the DisplayVideo.xaml I have written the code for fetching and playing the video file from Isolation Storage.

Isolation2.gif

Here when you will click the "Save file in IS" button a filedialog will open. You choose the image and it will store it into IsolationStorage. When you click the "Read file in IS" button it will fetch from the Isolation Location and will play it.

In this e.g. only .wmv video file will play.

When you click the button "Increase Quota" it will automatically increase the Isolation quota by 1gb.

For doing this operation I have created a separate class name SaveIsolation.cs. Where I have mentioned all the
necessary methods for fetching and displaying a file from isolation storage.

Isolation3.gif

Now In the MainPage.xaml I have added the DisplayVIdeo.xaml UserControl. In the figure below I marked it as Black. The Content of the Display Video will automatically come in.

Isolation4.gif

Place
<local:DisplayVideo x:Name="ucvideo"></local:DisplayVideo>

Code under the grid section.

Now To increase the IsolationStorage the method is:

//this method is for increase the isolation storaze size
        public bool Stor_IncreaseQuota(long bt)
        {
            try
            {
                using (IsolatedStorageFile oStore =
                       IsolatedStorageFile.GetUserStoreForApplication())
                {
                    // 5MB
                    long iQuotaCur = oStore.Quota;
                    ulong iQuotaCur1 = (ulong)oStore.Quota;
                    long iQuotaAvl = oStore.AvailableFreeSpace;
                    long gb = 1024 * 1024 * 1024;
                    long iQuotaNew = (gb + iQuotaAvl + bt);
                    ulong iQuotaNew1 = (ulong)iQuotaNew;

                    if (iQuotaNew1 > iQuotaCur1)
                    {
                        if (oStore.IncreaseQuotaTo(iQuotaNew) == true)
                        {
                            // The user clicked Yes to the
                            // host's prompt to approve the quota increase.
                            return true;
                        }
                        else
                        {
                            // The user clicked No to the
                            // host's prompt to approve the quota increase.
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            catch (IsolatedStorageException)
            {

                return false;
            }
        }

And finally to set the Application to the Out of browser application go to OutOfBrowserSettings.xml.

Under properties add this code:

<OutOfBrowserSettings ShortName="IsolationMediaElement Application" EnableGPUAcceleration="False" ShowInstallMenuItem="True">
  <OutOfBrowserSettings.Blurb>IsolationMediaElement Application on your desktop; at home, at work or on the go.</OutOfBrowserSettings.Blurb>
  <OutOfBrowserSettings.WindowSettings>
    <
WindowSettings Title="IsolationMediaElement Application" />
  </OutOfBrowserSettings.WindowSettings>
  <
OutOfBrowserSettings.Icons />
</
OutOfBrowserSettings>

Like as in the picture below.

Isolation5.gif

I have attached the Source Code here.

The Isolation path for Windows XP is...

C:\Documents and Settings\shirsendun\Local Settings\Application Data\Microsoft\Silverlight

Run the Code. I have chosen an image file and when the read button is clicked it looks like.

Isolation6.gif

Up Next
    Ebook Download
    View all
    Learn
    View all