My name is Edward Tanguay. I'm an American software and web developer living and working in Berlin, Germany.
SILVERLIGHT CODE EXAMPLE created on Friday, April 30, 2010 permalink
Code base for loading and caching external data into a silverlight app
This code is a nice start if you need a one-page silverlight control or application which loads text asynchronously and then caches it in IsolatedStorage so that the next time the user visits, the data is there. There is a clear cache button so that the data gets loaded again.
XAML:
<UserControl x:Class="TestLoadCache.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
     <StackPanel Margin="10">


        <TextBlock Text="{Binding Message}" Margin="0 0 0 10"/>

        <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Margin="0 0 0 10">
            <Button Content="Load Text" Click="Button_LoadText_Click" Margin="0 0 5 0"/>
            <Button Content="Clear Isolated" Click="Button_ClearIsolatedStorage_Click" Margin="0 0 5 0"/>
        </StackPanel>

        <TextBlock Text="{Binding LoadedText}" Margin="0 0 0 10"/>


    </StackPanel>
</UserControl>

Code Behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.IO.IsolatedStorage;
using System.IO;

namespace TestLoadCache
{
    public partial class MainPage : UserControl, INotifyPropertyChanged
    {
        #region ViewModelProperty: Message
        private string _message;
        public string Message
        {
            get
            {
                return _message;
            }

            set
            {
                _message = value;
                OnPropertyChanged("Message");
            }
        }
        #endregion .

        #region ViewModelProperty: LoadedText
        private string _loadedText;
        public string LoadedText
        {
            get
            {
                return _loadedText;
            }

            set
            {
                _loadedText = value;
                OnPropertyChanged("LoadedText");
            }
        }
        #endregion .



        public MainPage()
        {
            InitializeComponent();
            DataContext = this;
        }


        private void Button_ClearIsolatedStorage_Click(object sender, RoutedEventArgs e)
        {
            FileHelpers.ClearIsolatedStorage();
            Message = "IsolatedStorage cleared.";

            LoadedText = "";
        }


        private void Button_LoadText_Click(object sender, RoutedEventArgs e)
        {
            string url = "http://test.development:1111/testdata/test.txt".EnsureNoncachingForUrl();

            string isolatedStorageText = FileHelpers.LoadTextFromIsolatedStorageFile(url.ConvertUrlToFileName());

            if (!String.IsNullOrEmpty(isolatedStorageText))
            {
                LoadedText = isolatedStorageText;
                Message = "Text loaded from isolated storage.";
            }
            else
            {
                Message = "Loading from server...";
                WebClient webClientTextLoader = new WebClient();
                webClientTextLoader.DownloadStringAsync(new Uri(url), url);
                webClientTextLoader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClientTextLoader_DownloadStringCompleted);
            }

        }

        void webClientTextLoader_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            string url = e.UserState.ToString();
            string loadedText = e.Result;

            FileHelpers.SaveTextToIsolatedStorageFile(loadedText, url.ConvertUrlToFileName());
            LoadedText = loadedText;
            Message = "Text loaded from external site. ";
        }

        #region INotifiedProperty Block
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion .
    }


    public static class StringHelpers
    {
        public static string EnsureNoncachingForUrl(this string url)
        {
            int randomNumber = MathHelpers.GetRandomNumber(100000, 999999);
            if (!url.Contains("?"))
                return url + "?" + randomNumber;
            else
                return url + "&" + randomNumber;
        }

        /// <summary>
        /// converts e.g. http://test.development:11111/testdata/test.png?283748347 to httptestdevelopment22222testdatatestpng
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string ConvertUrlToFileName(this string url)
        {
            List<string> parts = url.BreakIntoParts("?");
            string returnString = parts[0];
            List<string> deletionCharacters = new List<string> {
                ":",
                "/",
                "."
            };
            foreach (var deletionCharacter in deletionCharacters)
            {
                returnString = returnString.Replace(deletionCharacter, "");
            }

            return returnString;
        }

        public static List<string> BreakIntoParts(this string line, string separator)
        {
            if (String.IsNullOrEmpty(line))
                return null;
            else
            {
                return line.Split(new string[] { separator }, StringSplitOptions.None).Select(p => p.Trim()).ToList();
            }
        }

    }

    public static class MathHelpers
    {
        private static Random random = new Random();
        public static int GetRandomNumber(int min, int max)
        {
            return random.Next(min, max + 1);
        }
    }

    public static class FileHelpers
    {
        public static bool SaveTextToIsolatedStorageFile(string text, string fileName)
        {
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(fileName, FileMode.Create, isf))
                {
                    using (StreamWriter sw = new StreamWriter(isfs))
                    {
                        try
                        {
                            sw.Write(text);
                        }
                        catch (IsolatedStorageException ex)
                        {
                            return false;
                        }
                        finally
                        {
                            sw.Close();
                        }
                    }
                }
                return true;
            }
        }

        public static string LoadTextFromIsolatedStorageFile(string fileName)
        {
            string text = String.Empty;

            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!isf.FileExists(fileName))
                    return "";

                using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(fileName, FileMode.Open, isf))
                {
                    using (StreamReader sr = new StreamReader(isfs))
                    {
                        string lineOfData = String.Empty;
                        while ((lineOfData = sr.ReadLine()) != null)
                            text += lineOfData + Environment.NewLine;
                    }
                }
                return text;
            }
        }

        public static void ClearIsolatedStorage()
        {
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                string[] fileNames = isf.GetFileNames();

                foreach (var fileName in fileNames)
                {
                    isf.DeleteFile(fileName);
                }
            }
        }

    }
}
need markup?