views:

668

answers:

1

Hi ... is it possible to save images in a webbroswer control directly to harddisk, without needing to download them again from the internet ?

lets say i navigate to a website, that has 15images, they are all viewed in my webbrowser, but how can i save them now without the need to download them? hope my question is clear thanks in advance

A: 

This is the only way I could find. Curious if anyone else has a better way.

Copied from CodeProject

You have to add a reference to Microsoft.mshtml and of course wait for the document to finish loading. This will save the images loaded in a System.Windows.Forms.WebBrowser webBrowser1 component - even the ones you don't want.


IHTMLDocument2 doc = (IHTMLDocument2) webBrowser1.Document.DomDocument;
IHTMLControlRange imgRange = (IHTMLControlRange) ((HTMLBody) doc.body).createControlRange();

foreach (IHTMLImgElement img in doc.images)
{
  imgRange.add((IHTMLControlElement) img);

  imgRange.execCommand("Copy", false, null);

  using (Bitmap bmp = (Bitmap) Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
  {
    bmp.Save(@"C:\"+img.nameProp);
  }
}
Asher
hi ...thanks for replying,i just hope that someone will come up with another solution, as i really cant use the clipboard like that ...
lebhero
well if the clipboard is off limits, then other than going through the cache, the only other way may be to download the image again. But lets see what others come up with
Asher