title: "Closing" files in IsolatedStorage before deleting them
body: <p>I'm writing an app for Windows Phone 7 in which I save images to Isolated Storage.
  When I load them, I can't close the opened image streams because other parts of my program need to be able to read them in order to properly display the images.
  I only want to close these streams when I'm getting ready to delete/alter the files themselves in Isolated Storage. </p>
  
  <p>However, by the time I'm ready to delete these images, I no longer have access to the local IsolatedStorageFileStream variables I was using when I opened them. </p>
  
  <p>Is there a way to somehow "close" these files at this point (besides restarting my application)? I can't seem to delete them otherwise.</p>
  
  <p>This is how I write the images into IsolatedStorage:</p>
  
  <pre><code>    Dictionary&lt;string, Stream&gt; imageDict = (Dictionary&lt;string, Stream&gt;)Globals.CNState["ATTACHMENT"];
      foreach (string pic in imageDict.Keys)
      {
        Stream input = imageDict[pic];
        input.Position = 0;
        byte[] buffer = new byte[16*1024];
  
        using (FileStream thisStream = myISF.OpenFile(thisDirectory + pic, FileMode.Create))
        {
          int read = input.Read(buffer, 0, buffer.Length);
          while (read &gt; 0)
          {
            thisStream.Write(buffer, 0, read);
            read = input.Read(buffer, 0, buffer.Length);
          }
        }
      }
  </code></pre>
  
  <p>This is how I load them out later (as you can see, I keep them open):</p>
  
  <pre><code>  string[] storedImages = myISF.GetFileNames(thisDirectory);
    if(storedImages.Length &gt; 0)
    {
      foreach(string pic in storedImages)
      {
        IsolatedStorageFileStream imageStream = myISF.OpenFile(thisDirectory + pic, FileMode.Open, FileAccess.Read, FileShare.Read);
        imageDict.Add(pic, imageStream);
      }
    }
  
    Globals.CNState["ATTACHMENT"] = imageDict;
  </code></pre>
  
  <p>I can't close these because another part of my application needs to create the images from their file streams (this may need to happen multiple times):</p>
  
  <pre><code>  if (Globals.CNState != null &amp;&amp; Globals.CNState.ContainsKey("ATTACHMENT"))
    {
      imageDict = (Dictionary&lt;string, Stream&gt;)Globals.CNState["ATTACHMENT"];
      foreach (string key in imageDict.Keys)
      {
        Stream imageStream = imageDict[key];
  
        Image pic = new Image();
        pic.Tag = key;
        BitmapImage bmp = new BitmapImage();
        bmp.SetSource(imageStream);
        pic.Source = bmp;
        pic.Margin = new Thickness(0, 0, 0, 15);
        pic.MouseLeftButtonUp += new MouseButtonEventHandler(pic_MouseLeftButtonUp);
        DisplayPanel.Children.Add(pic);
      }
    }
  </code></pre>
  
  <p>I also need to keep the streams open because another part of my program sends these images to a server, and as far as I know, I can only send a byte stream, not a UIElement.</p>