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 image from wewbsite

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Johnny Jörgensen - 16 Nov 2007 17:02 GMT
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.
Mythran - 16 Nov 2007 17:29 GMT
> 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
Cor Ligthert[MVP] - 16 Nov 2007 17:49 GMT
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
Herfried K. Wagner [MVP] - 16 Nov 2007 20:09 GMT
"Johnny Jörgensen" <jojo@altcom.se> 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.

Signature

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

Johnny Jörgensen - 16 Nov 2007 21:16 GMT
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.

> 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.
Nicholas Paldino [.NET/C# MVP] - 17 Nov 2007 04:09 GMT
Johnny,

   The following will help you do what you want:

http://msdn2.microsoft.com/en-us/library/bb250487.aspx#webteam03052001_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.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Thanks for the suggestions all of you.
>
[quoted text clipped - 16 lines]
>> Cheers,
>> Johnny J.
Cor Ligthert[MVP] - 17 Nov 2007 13:10 GMT
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
Johnny Jörgensen - 17 Nov 2007 22:18 GMT
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.

> Johnny,
>
[quoted text clipped - 5 lines]
>
> Cor
Joey Joe Joe - 18 Nov 2007 00:42 GMT
That's exactly where they are. They're in your Temporary Internet Files
folder.

> 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
[quoted text clipped - 23 lines]
>>
>> Cor
Cor Ligthert[MVP] - 18 Nov 2007 15:34 GMT
> That's exactly where they are. They're in your Temporary Internet Files
> folder.

Which you could find in W98 and IE4 direct in the C drive folder, however a
little bit changed.

In XP it has all kind of GUID like other names, in Vista I don't even see it
even anymore.

Beside that are images mostly very short in cache because that they have
mostly a retention time of 0.

Cor
Joey Joe Joe - 18 Nov 2007 16:38 GMT
That's because the folder is hidden, but it's still there. In Vista (unless
you move it):

C:\Users\.....\AppData\Local\Microsoft\Windows\Temporary Internet Files

>> That's exactly where they are. They're in your Temporary Internet Files
>> folder.
[quoted text clipped - 9 lines]
>
> Cor
Lloyd Sheen - 18 Nov 2007 17:47 GMT
> That's because the folder is hidden, but it's still there. In Vista
> (unless you move it):
[quoted text clipped - 14 lines]
>>
>> Cor

Simplest way to find the temp files in Vista is to use Tools/Internet
Options/General Tab.

Click on Settings then View Files

LS
Cor Ligthert[MVP] - 18 Nov 2007 18:15 GMT
Lloyd Sheen - 18 Nov 2007 00:47 GMT
> 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
[quoted text clipped - 23 lines]
>>
>> 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
Trevor Benedict - 19 Nov 2007 17:43 GMT
Johnny,
Since the image is already cached and the solution provided is to download
it using the URL, when you send the request to the server, you may still end
up getting the file from the Cache. Except for the call to the server, you
might still be reusing the downloaded image.

Regards,

Trevor Benedict
MCSD

> 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
[quoted text clipped - 23 lines]
>>
>> Cor

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.