title: Drag and Drop image from browser to WPF Application
body: <p>I'm trying to implement functionality in my WPF application to drag an image out of a browser and into a window in my WPF app. </p>
  
  <p>The code works fine with Firefox and Windows Explorer, but issues arise with Chrome and IE (haven't tried any other browsers just yet).</p>
  
  <p>Here's a code snippet:</p>
  
  <pre><code>private void Drag_Enter(object sender, DragEventArgs e)
  {
      foreach (string format in e.Data.GetFormats())
          Console.WriteLine(format);
      Console.WriteLine("Effects:" + e.AllowedEffects);
  }
  
  private void Drag_Drop(object sender, DragEventArgs e)
  {
      string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
      ImageSourceConverter converter = new ImageSourceConverter();
      foreach (string file in files)
      {
          if (converter.IsValid(file))
          {
              // Do something with the image
          }
      }
   }
  </code></pre>
  
  <p>Looking at the output, it seems that Firefox actually saves the image to the clipboard, whereas Chrome is just grabbing the html of the image, while IE doesn't do anything with it.</p>
  
  <p>Anyone have some insight as to how I may get cross-browser functionality?</p>
  
  <hr>
  
  <p><strong>Update</strong>: 
  A couple of workarounds I've found are to parse the html (Chrome/Firefox) for an image source, then download from the source using something like the WebClient object.
  Would prefer a method, though, that has stronger checking for file type.</p>
  
  <p>IE9 and Firefox both have a DeviceIndependentBitmap file format that is available when dragging an non-hyperlink image. This seems to be a safer alternative, though Chrome does not seem to support it. It is also not so useful with hyperlink images.</p>
  
  <hr>
  
  <p>With Firefox, the output is (Drag_Enter for some reason gets fired twice):</p>
  
  <pre><code>text/x-moz-url
  FileGroupDescriptor
  FileGroupDescriptorW
  FileContents
  UniformResourceLocator
  UniformResourceLocatorW
  text/x-moz-url-data
  text/x-moz-url-desc
  text/uri-list
  text/_moz_htmlcontext
  text/_moz_htmlinfo
  text/html
  HTML Format
  Text
  UnicodeText
  System.String
  application/x-moz-nativeimage
  DeviceIndependentBitmap
  FileDrop
  FileNameW
  FileName
  Preferred DropEffect
  application/x-moz-file-promise-url
  application/x-moz-file-promise-dest-filename
  DragImageBits
  DragContext
  Effects: Link, All
  </code></pre>
  
  <p>Chrome (drag_enter also gets fired twice):</p>
  
  <pre><code>DragContext
  DragImageBits
  FileGroupDescriptorW
  FileContents
  HTML Format
  text/html
  text/x-moz-url
  UniformResourceLocatorW
  UniformResourceLocator
  Text
  UnicodeText
  System.String
  Effects: Copy, Move, Link
  </code></pre>
  
  <p>Internet Explorer (again, drag_enter fired twice):</p>
  
  <pre><code>UntrustedDragDrop
  msSourceUrl
  FileGroupDescriptor
  FileGroupDescriptorW
  FileContents
  UniformResourceLocator
  Effects: Link
  </code></pre>