download jpg via C#

22 views
Skip to first unread message

john

unread,
Jun 30, 2003, 3:40:01 PM6/30/03
to
Can someone show be a link or some code on how to download
an image file via C#?

I've successfully created a HttpWebRequest object that
points to the url of the jpg. then i've created a
HttpWebResponse object that is returned when i call
GetResponse() on the request object.

but once i have the HttpWebResponse object, i dont know
how to get the binary data for the jpg out and save it to
a file. thanks for any help

nahum takum

unread,
Jun 30, 2003, 5:18:55 PM6/30/03
to
1. try this link at VS.Net
ms-help://MS.VSCC/MS.MSDNVS/cpgenref/html/cpconhtmlinputfilecontrol.htm

2. Search for WebClient.UploadFile

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

john farrow

unread,
Jun 30, 2003, 5:37:10 PM6/30/03
to
Something like this:

System.Uri uri = new System.Uri( http://www.whatever.com/image.jpg );

WebRequest request = WebRequest.Create( uri );

WebResponse response = request.GetResponse();

Stream str = response.GetResponseStream();

// save to file

Stream output = new FileStream( ... ) ;

byte[] buff = new byte[ BUFFER_SIZE ];


int bytes = 0;

while( ( bytes = str.Read( buff, 0, BUFFER_SIZE ) ) > 0 ) {

output.Write( buff, 0, bytes );

}

output.Close();

"john" <jo...@john.com> wrote in message
news:03d801c33f3f$65728780$a101...@phx.gbl...

Reply all
Reply to author
Forward
0 new messages