title: How to display an image from a network folder or local drive in a Windows Universal App
body: <p>I'm having trouble displaying an jpg in an Image control in a Windows Universal App. (I had the same problem trying to create a Windows 8 Store app as well)</p>
  
  <p>I have a simple form with an Image control on it. All I want to do is be able to open images in a folder on my local drive or a network drive on my local network and display them. But I am not having any luck. The only thing I get is E_NETWORK_ERROR, with no additional information.</p>
  
  <p>I assume it probably has something to do with security, but surely there must be a setting or permission to allow me to do it. I tried enabling Private Networks in the Capabilities tab of the manifest, but that didn't help. I don't see anything in Declarations that sounds like what I need. </p>
  
  <p>I know UWP apps are somewhat sandboxed, but if you can't even access local files, what good are they?</p>
  
  <p>Here is a sample of code I have tried. I've done other iterations as well, but they all have the same end result.</p>
  
  <p>Xaml:</p>
  
  <pre><code>&lt;Image Name="Image1"/&gt;
  </code></pre>
  
  <p>Code behind:</p>
  
  <pre><code>    public LoadImage()
      {
          var bitmap = new BitmapImage();
          bitmap.ImageFailed += Bitmap_ImageFailed;
          bitmap.UriSource = new Uri(@"D:\Users\Steve\Documents\SomeImage.JPG", UriKind.Absolute);
          Image1.Source = bitmap;
      }
  
      private void Bitmap_ImageFailed(object sender, ExceptionRoutedEventArgs e)
      {
          Debug.Write(e.ErrorMessage);
      }
  </code></pre>
  
  <p>When I run it, I end up in the Bitmap_ImageFailed event and the ErrorMessage property is simply "E_NETWORK_ERROR", and nothing is displayed in the Image. Not very helpful.</p>
  
  <p>What am I missing? It has to be something simple and obvious that I am overlooking.</p>
  
  <p>Update:</p>
  
  <p>Thanks to all the suggestions here I was able to get it going. The part I was failing to get through my skull was that you can't just give it a folder and expect it to read a file, even as a "quick &amp; dirty test". You have to go through "proper channels" to get there. I pieced it all together and came up with this example which displays the first image in the selected folder:</p>
  
  <pre><code>    private async void Button_Click(object sender, RoutedEventArgs e)
      {
          FolderPicker folderPicker = new FolderPicker();
          folderPicker.SuggestedStartLocation = PickerLocationId.Desktop;
          folderPicker.FileTypeFilter.Add(".jpg");
          folderPicker.FileTypeFilter.Add(".tif");
          folderPicker.FileTypeFilter.Add(".png");
  
          StorageFolder folder = await folderPicker.PickSingleFolderAsync();
          if (folder != null)
          {
              StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
              var files = await folder.GetFilesAsync();
  
              var bitmap = new BitmapImage();
              bitmap.ImageFailed += Bitmap_ImageFailed;
              var stream = await files.First().OpenReadAsync();
              await bitmap.SetSourceAsync(stream);
              Image1.Source = bitmap;
          }
      }
  </code></pre>
  
  <p>In addition, I had to add the file types for .jpg, .tif and .png as well as File Open Picker to the Declarations.</p>