Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2007

Tip: Looking for answers? Try searching our database.

Getting an Image from webBrowser.DocumentStream

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jwgoerlich@gmail.com - 06 Nov 2007 23:10 GMT
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
Peter Bromberg [C# MVP] - 07 Nov 2007 01:13 GMT
You can Authenticate with WebRequest and even with WebClient, you just need
to add a NetworkCredentials object. Don't make it hard on yourself.

-- Peter
http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder:    http://www.blogmetafinder.com

> Hello group,
>
[quoted text clipped - 22 lines]
>
> J Wolfgang Goerlich
jwgoerlich@gmail.com - 07 Nov 2007 13:31 GMT
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

On Nov 6, 8:13 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.NoSpamMaam.com> wrote:
> You can Authenticate with WebRequest and even with WebClient, you just need
> to add a NetworkCredentials object. Don't make it hard on yourself.
[quoted text clipped - 32 lines]
>
> - Show quoted text -

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.