473,473 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Saving image to file from a webpage

I cant seem to find the commmand that I can use to save an image file
from a url to my local harddrive. I am looking to save a jpg from a
webpage that I have screen scraped.
I have a web application that uses readHtmlPage(url.ToString()); to
read the page in, I am able to use regular expressions to save to url
of the jpg to a string but I cant seem to find the way to save that
image to a file on my local drive

What I want to do is, if I have:

strJPGURL="http://www.website.com/images/*image123.jpg"
how can I save that to
f::/images/image123.jpg

Thanks..
Rich

Nov 17 '05 #1
4 2115

The usual disclaimer apples here - this was written by me so it's probably wrong. It
could do this task better - it could use async callbacks and all that gubbins. I don't
know how to use that (If anyone out there can post a better example with better
explinations that the one in the SDK I'll be VERY greatful - Async Callbacks have me
stumped).

But it works and it will stream an image from the interweb for you - just pass it the url.
From there just write it to a file.

-- BEGIN CODE --

private Image StreamImageFromNet(string url)
{
Image img = null;
Stream str = null;

System.Console.WriteLine("Retreiving: " + url);

HttpWebRequest webReq;
webReq =
(HttpWebRequest)HttpWebRequest.Create(url);

try
{
HttpWebResponse webResp =
(HttpWebResponse)webReq.GetResponse();
str = webResp.GetResponseStream();

img = Image.FromStream(str);

System.Console.WriteLine("That went off
without a hitch");
}
catch (WebException ex)
{
// Do something more important here
System.Console.WriteLine(ex.Message);
}
finally
{
if (str != null)
str.Close();
return img;
}

-- END CODE --

<td*******@yahoo.com> wrote:
I cant seem to find the commmand that I can use to save an image file
from a url to my local harddrive. I am looking to save a jpg from a
webpage that I have screen scraped.
I have a web application that uses readHtmlPage(url.ToString()); to
read the page in, I am able to use regular expressions to save to url
of the jpg to a string but I cant seem to find the way to save that
image to a file on my local drive

What I want to do is, if I have:

strJPGURL="http://www.website.com/images/*image123.jpg"
how can I save that to
f::/images/image123.jpg

Thanks..
Rich

------------------------------------

Another unchecked rambeling brought to you by:

Oddball
joshua@bf#N0SP4M#wd.co.uk
Nov 17 '05 #2
A good example of asynchronous web requests:
http://msdn.microsoft.com/library/de...usRequests.asp

I really wouldn't recommend async transfer here anyway, as for some
images you need the entire stream before you can build the image.
The usual disclaimer apples here - this was written by me so it's probably wrong. It
could do this task better - it could use async callbacks and all that gubbins. I don't
know how to use that (If anyone out there can post a better example with better
explinations that the one in the SDK I'll be VERY greatful - Async Callbacks have me
stumped).

Nov 17 '05 #3
Hi Rich,

In Addition to Oddballs example of using WebRequest, there is always the

WebClient.DownloadFile(url, localfilename)

It is less flexible than WebRequest/Response but far easier to use.
On Sat, 25 Jun 2005 14:21:40 +0200, <td*******@yahoo.com> wrote:
I cant seem to find the commmand that I can use to save an image file
from a url to my local harddrive. I am looking to save a jpg from a
webpage that I have screen scraped.
I have a web application that uses readHtmlPage(url.ToString()); to
read the page in, I am able to use regular expressions to save to url
of the jpg to a string but I cant seem to find the way to save that
image to a file on my local drive

What I want to do is, if I have:

strJPGURL="http://www.website.com/images/*image123.jpg"
how can I save that to
f::/images/image123.jpg

Thanks..
Rich



--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #4

Crikey - that is easy isn't it....

Nice one Morten!
------------------------------------

Another unchecked rambeling brought to you by:

Oddball
joshua@bf#N0SP4M#wd.co.uk
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: LC | last post by:
Hi, I would like to know how I can save my current ASP page to the server side in html file format. Then I would like to stream it back to the client side. Any help is very much...
2
by: LC | last post by:
Hi, Many Weeks ago I posted this: I would like to know how I can save my current ASP page to the server side in html file format. I got a very nice reply back from Scott McNair. Thank you...
4
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+....
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
5
by: TheGanjaMan | last post by:
Hi everyone, I'm trying to write up a simple image stamper application that stamps the Exif date information from the jpegs that I've taken from my digital camera and saves the new file with the...
6
by: Jeff | last post by:
Hey (and thank you for reading my post) In visual web developer 2005 express edition I've created a simple website project.. At this website I want users who register to be able to upload a...
6
by: Mark Denardo | last post by:
My question is similar to one someone posted a few months back, but I don't see any replies. Basically I want to be able to have users upload photos and save them in a database (as byte data)...
6
by: Eddie | last post by:
Hi all, I am displaying a number of reports, and giving the users an option to display them on the web or download them to Excel. If they want the Excel file, I just use the PHP header command...
10
by: Nathan Sokalski | last post by:
I am using ASP.NET 2.0, and need to know how to save and use an image that is stored in an SQL Server image datatype. How can I do this using ASP.NET? Thanks.
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.