Getting image from wewbsite

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Johnny Jörgensen

    #1

    Getting image from wewbsite

    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

    #2
    Re: Getting image from wewbsite



    "Johnny Jörgensen" <jojo@altcom.se wrote in message
    news:Ot3LSKHKIH A.3672@TK2MSFTN GP02.phx.gbl...
    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....firs t,
    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.c a.us/CountyWeb/images/GeneralActive.g if";
    HttpWebRequest request =
    (HttpWebRequest ) WebRequest.Crea te(url);
    HttpWebResponse response =
    (HttpWebRespons e) request.GetResp onse();

    byte[] bytes;
    using (Stream stream = response.GetRes ponseStream()) {
    bytes = new byte[response.Conten tLength];
    stream.Read(byt es, 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



    Comment

    • Cor Ligthert[MVP]

      #3
      Re: Getting image from wewbsite

      Johny,

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

      DownloadFile
      http://msdn2.microsoft.com/en-us/lib...le(VS.71).aspx

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



      Cor

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Getting image from wewbsite

        "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.Ne twork.DownloadF ile'
        'System.Net.Web Client.Download File'

        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/>

        Comment

        • Johnny Jörgensen

          #5
          Re: Getting image from wewbsite

          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" <jojo@altcom.se skrev i meddelandet
          news:Ot3LSKHKIH A.3672@TK2MSFTN GP02.phx.gbl...
          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.
          >

          Comment

          • Nicholas Paldino [.NET/C# MVP]

            #6
            Re: Getting image from wewbsite

            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]
            - mvp@spam.guard. caspershouse.co m

            "Johnny Jörgensen" <jojo@altcom.se wrote in message
            news:Od3NaYJKIH A.280@TK2MSFTNG P03.phx.gbl...
            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" <jojo@altcom.se skrev i meddelandet
            news:Ot3LSKHKIH A.3672@TK2MSFTN GP02.phx.gbl...
            >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.
            >>
            >
            >

            Comment

            • Cor Ligthert[MVP]

              #7
              Re: Getting image from wewbsite

              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

              Comment

              • Cor Ligthert[MVP]

                #8
                Re: Getting image from wewbsite


                "Joey Joe Joe" <no@nothing.com schreef in bericht
                news:%23Tr1ivXK IHA.280@TK2MSFT NGP03.phx.gbl.. .
                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

                Comment

                • Joey Joe Joe

                  #9
                  Re: Getting image from wewbsite

                  That's because the folder is hidden, but it's still there. In Vista (unless
                  you move it):

                  C:\Users\.....\ AppData\Local\M icrosoft\Window s\Temporary Internet Files

                  "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
                  news:A77391F8-8E07-44EE-B661-9FBCF795DDA8@mi crosoft.com...
                  >
                  "Joey Joe Joe" <no@nothing.com schreef in bericht
                  news:%23Tr1ivXK IHA.280@TK2MSFT NGP03.phx.gbl.. .
                  >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

                  Comment

                  • Lloyd Sheen

                    #10
                    Re: Getting image from wewbsite


                    "Joey Joe Joe" <no@nothing.com wrote in message
                    news:umCuqFgKIH A.3516@TK2MSFTN GP02.phx.gbl...
                    That's because the folder is hidden, but it's still there. In Vista
                    (unless you move it):
                    >
                    C:\Users\.....\ AppData\Local\M icrosoft\Window s\Temporary Internet Files
                    >
                    "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
                    news:A77391F8-8E07-44EE-B661-9FBCF795DDA8@mi crosoft.com...
                    >>
                    >"Joey Joe Joe" <no@nothing.com schreef in bericht
                    >news:%23Tr1ivX KIHA.280@TK2MSF TNGP03.phx.gbl. ..
                    >>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
                    >
                    Simplest way to find the temp files in Vista is to use Tools/Internet
                    Options/General Tab.

                    Click on Settings then View Files

                    LS

                    Comment

                    • Cor Ligthert[MVP]

                      #11
                      Re: Getting image from wewbsite

                      Thanks Lloyd,

                      Comment

                      Working...