Getting an Image from webBrowser.DocumentStream

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
 
J

jwgoerlich

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top