PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

Getting image from wewbsite

 
 
Johnny Jörgensen
Guest
Posts: n/a
 
      16th Nov 2007
Does anybody know how you can extract an image fron a webpage loaded into a
webbrowser control and either save it to file OR save it in a database?

Cheers,
Johnny J.


 
Reply With Quote
 
 
 
 
Mythran
Guest
Posts: n/a
 
      16th Nov 2007


"Johnny Jörgensen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Does anybody know how you can extract an image fron a webpage loaded into
> a webbrowser control and either save it to file OR save it in a database?
>
> Cheers,
> Johnny J.
>


You need to read in the image as if you were reading in a webpage....first,
open the web page and parse the path to the image...then, you can use the
following code to get the byte-array of the image and store to a file or
data column in a database.

// BEGIN C#

string url =
@"http://www.co.merced.ca.us/CountyWeb/images/GeneralActive.gif";
HttpWebRequest request =
(HttpWebRequest) WebRequest.Create(url);
HttpWebResponse response =
(HttpWebResponse) request.GetResponse();

byte[] bytes;
using (Stream stream = response.GetResponseStream()) {
bytes = new byte[response.ContentLength];
stream.Read(bytes, 0, bytes.Length);
}

// Now we have a byte array to do as we wish, saving to a file
now.
FileStream fs = File.Create(@"C:\GeneralActive.gif");
fs.Write(bytes, 0, bytes.Length);
fs.Close();

// OR write to a database.
// To do this, create an IMAGE (SQL Server) column and just copy
// the byte array into the field for a DataRow. An Image column
// maps to a byte-array in a DataColumn in a DataRow.

// END C#

There may be an easier or better way in a more recent version of the .Net
Framework though...


HTH,
Mythran



 
Reply With Quote
 
 
 
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      16th Nov 2007
Johny,

As soon as you know its url location you can download it using

DownloadFile
http://msdn2.microsoft.com/en-us/library/system.net.webclient.downloadfile(VS.71).aspx

To get that in a webbrowser you mostly needs a lot of mshtml

http://support.microsoft.com/kb/311284

Cor

 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      16th Nov 2007
"Johnny Jörgensen" <(E-Mail Removed)> schrieb:
> Does anybody know how you can extract an image fron a webpage loaded into
> a webbrowser control and either save it to file OR save it in a database?


'My.Computer.Network.DownloadFile'
'System.Net.WebClient.DownloadFile'

You can store the binary data in the database as a BLOB.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

 
Reply With Quote
 
Johnny Jörgensen
Guest
Posts: n/a
 
      16th Nov 2007
Thanks for the suggestions all of you.

Howevet, having had time to think about it, it seems like I'm missing
something here.

You see, as I wrote, I already have a webpage loaded in a webbrowser
containing the image I want to save to a database field.

So there should be no reason for downloading it AGAIN (using extra time to
do that). There MUST be a way to "pluck out" the image from the webbrowser
control in a form that's database saveable.

Cheers,
Johnny J.





"Johnny Jörgensen" <(E-Mail Removed)> skrev i meddelandet
news:(E-Mail Removed)...
> Does anybody know how you can extract an image fron a webpage loaded into
> a webbrowser control and either save it to file OR save it in a database?
>
> Cheers,
> Johnny J.
>



 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      17th Nov 2007
Johnny,

The following will help you do what you want:

http://msdn2.microsoft.com/en-us/lib...3052001_topic2

Be aware, however, that because of security issues, the UI to indicate
where to save the image must be presented, there is no way around it.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Johnny Jörgensen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks for the suggestions all of you.
>
> Howevet, having had time to think about it, it seems like I'm missing
> something here.
>
> You see, as I wrote, I already have a webpage loaded in a webbrowser
> containing the image I want to save to a database field.
>
> So there should be no reason for downloading it AGAIN (using extra time to
> do that). There MUST be a way to "pluck out" the image from the webbrowser
> control in a form that's database saveable.
>
> Cheers,
> Johnny J.
>
>
>
>
>
> "Johnny Jörgensen" <(E-Mail Removed)> skrev i meddelandet
> news:(E-Mail Removed)...
>> Does anybody know how you can extract an image fron a webpage loaded into
>> a webbrowser control and either save it to file OR save it in a database?
>>
>> Cheers,
>> Johnny J.
>>

>
>


 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      17th Nov 2007
Johnny,

There is no image loaded in your webbrowser, a webbrowser is just using the
IE part of the OS. In the pages there is an image tag to the url about we
all are talking about in a way. That URL you can find using MSHTML (Which is
nothing more then the representation of the DHTML object model often called
***the*** DOM).

Cor

 
Reply With Quote
 
Johnny Jörgensen
Guest
Posts: n/a
 
      17th Nov 2007
Cor, you're not making sense - are you trying to tell me that the image I
see in the Webbrowser rendering of the HTML is not really there? Have I
started imagining things?

I certainly don't see the URL directly in the webbrowser (but I do of course
see it using the HTML document property. But the Webbrowser is rendering and
showing the HTML elements, which means that the picture I see in the webpage
must be some sort of an Image object that should be possible to reference.

All the solutions I've been given are using the same appoach: To use the URL
in the HTML to download the file off the internet. But don't you see: The
file has already been downloaded once! Why should I download it again? It
ought to be in the Internet file cache?

Cheers,
Johnny J.




"Cor Ligthert[MVP]" <(E-Mail Removed)> skrev i meddelandet
news:0945FE55-470B-4CC9-8078-(E-Mail Removed)...
> Johnny,
>
> There is no image loaded in your webbrowser, a webbrowser is just using
> the IE part of the OS. In the pages there is an image tag to the url about
> we all are talking about in a way. That URL you can find using MSHTML
> (Which is nothing more then the representation of the DHTML object model
> often called ***the*** DOM)
>
> Cor



 
Reply With Quote
 
Joey Joe Joe
Guest
Posts: n/a
 
      18th Nov 2007
That's exactly where they are. They're in your Temporary Internet Files
folder.

"Johnny Jörgensen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Cor, you're not making sense - are you trying to tell me that the image I
> see in the Webbrowser rendering of the HTML is not really there? Have I
> started imagining things?
>
> I certainly don't see the URL directly in the webbrowser (but I do of
> course see it using the HTML document property. But the Webbrowser is
> rendering and showing the HTML elements, which means that the picture I
> see in the webpage must be some sort of an Image object that should be
> possible to reference.
>
> All the solutions I've been given are using the same appoach: To use the
> URL in the HTML to download the file off the internet. But don't you see:
> The file has already been downloaded once! Why should I download it again?
> It ought to be in the Internet file cache?
>
> Cheers,
> Johnny J.
>
>
>
>
> "Cor Ligthert[MVP]" <(E-Mail Removed)> skrev i meddelandet
> news:0945FE55-470B-4CC9-8078-(E-Mail Removed)...
>> Johnny,
>>
>> There is no image loaded in your webbrowser, a webbrowser is just using
>> the IE part of the OS. In the pages there is an image tag to the url
>> about we all are talking about in a way. That URL you can find using
>> MSHTML (Which is nothing more then the representation of the DHTML object
>> model often called ***the*** DOM)
>>
>> Cor

>
>


 
Reply With Quote
 
Lloyd Sheen
Guest
Posts: n/a
 
      18th Nov 2007

"Johnny Jörgensen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Cor, you're not making sense - are you trying to tell me that the image I
> see in the Webbrowser rendering of the HTML is not really there? Have I
> started imagining things?
>
> I certainly don't see the URL directly in the webbrowser (but I do of
> course see it using the HTML document property. But the Webbrowser is
> rendering and showing the HTML elements, which means that the picture I
> see in the webpage must be some sort of an Image object that should be
> possible to reference.
>
> All the solutions I've been given are using the same appoach: To use the
> URL in the HTML to download the file off the internet. But don't you see:
> The file has already been downloaded once! Why should I download it again?
> It ought to be in the Internet file cache?
>
> Cheers,
> Johnny J.
>
>
>
>
> "Cor Ligthert[MVP]" <(E-Mail Removed)> skrev i meddelandet
> news:0945FE55-470B-4CC9-8078-(E-Mail Removed)...
>> Johnny,
>>
>> There is no image loaded in your webbrowser, a webbrowser is just using
>> the IE part of the OS. In the pages there is an image tag to the url
>> about we all are talking about in a way. That URL you can find using
>> MSHTML (Which is nothing more then the representation of the DHTML object
>> model often called ***the*** DOM)
>>
>> Cor

>
>


Sorry but he totally correct. While the file is in your cache there is no
image in the document. The items in the document simply tell the browser
what to render. When it hits the img tag it gets the downloaded image from
the cache and displays it. As for extra time if you need to download the
file it should recognise that it exists already and use the item in the
cache.

LS

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting image from wewbsite Johnny Jörgensen Microsoft C# .NET 15 7th Dec 2008 04:12 PM
Anyone web based image back up services or Acronis Drive Image 7.0 vs Symantec Drive Image 7.0 FransHals Computer Hardware 5 25th Jun 2004 02:51 AM
Anyone web based image back up services or Acronis Drive Image 7.0 vs Symantec Drive Image 7.0 FransHals Storage Devices 5 25th Jun 2004 02:51 AM
Acronis True Image 7.0: Image verify, and bootable DVD image write? Matt Windows XP General 14 16th Jan 2004 04:08 AM
Acronis True Image 7.0: Image verify, and bootable DVD image write? Matt Storage Devices 12 16th Jan 2004 01:19 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:12 PM.