Getting an Image from webBrowser.DocumentStream

  • Thread starter Thread starter jwgoerlich
  • Start date Start date
J

jwgoerlich

Hello group,

I am working with images on a website which uses cookie-based
authentication. I would like to programmatically download and save the
image. I am using a webBrowser rather than a HttpWebRequest because of
the authentication.

My code is as follows:

webBrowser.Url = new Uri("http://www.somewhere.com/images/
myimage.png");
do
{
System.Threading.Thread.Sleep(100);
} while (webBrowser.IsBusy || !webBrowser.DocumentStream.CanRead);
Bitmap i = new Bitmap(webBrowser.DocumentStream);
i.Save("myimage.png", ImageFormat.Png);

When I feed the DocumentStream into the new image, however, the code
fails with "Parameter is not valid."

What is the best way to download an image from the web?

Thanks in advance,

J Wolfgang Goerlich
 
Thanks for the response. It is form-based authentication and, so far
as I can tell, I cannot authenticate with the WebRequest. Is there any
way to pass the session from a WebBrowser to the WebRequest?

J Wolfgang Goerlich
 
Back
Top