Save image from a webpage????

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Laszlo Csabi

    #1

    Save image from a webpage????

    Hi guys,

    Anyone knows about how to save a picture from a html page to the hard disk
    either in C# or VB.NET? What I have done so far is the following and it
    doesn't work. I got an empty image created on the HDD.

    _webRequest =
    CType(Net.WebRe quest.Create("h ttp://wdz.whereis.com .au/gns?user=demo&p ass=de
    mo&geolang=en&f unction=map&mod e=server_1.2&wg s84x1y1=-37.820130359563 16|144.
    98320052639244& radius=800&widt h=400&height=40 0&format=gif&no url=1),
    Net.HttpWebRequ est)

    _webResponse = CType(_webReque st.GetResponse( ), Net.HttpWebResp onse)
    _stream = _webResponse.Ge tResponseStream

    Dim inBuf(100000) As Byte
    Dim bytesToRead As Integer = CInt(inBuf.Leng th)
    Dim bytesRead As Integer = 0

    While bytesToRead > 0
    Dim n As Integer = _stream.Read(in Buf, bytesRead, bytesToRead)
    If n = 0 Then
    Exit While
    End If
    bytesRead += n
    bytesToRead -= n
    End While

    If Not IO.Directory.Ex ists(Me.GiveFil ePath) = True Then
    IO.Directory.Cr eateDirectory(M e.GiveFilePath)
    End If

    _fileStream = New IO.FileStream(M e.GiveFilePath & "\map.gif",
    IO.FileMode.Ope nOrCreate, IO.FileAccess.W rite)
    _fileStream.Wri te(inBuf, 0, bytesRead)

    _webResponse.Cl ose()
    _fileStream.Clo se()


    Thanks

    Laszlo


  • Dmitriy Lapshin [C# / .NET MVP]

    #2
    Re: Save image from a webpage????

    Hi,

    Probably you need to pass some cookies along with the request?

    --
    Dmitriy Lapshin [C# / .NET MVP]
    X-Unity Test Studio

    Bring the power of unit testing to VS .NET IDE

    "Laszlo Csabi" <lcsabi@fantasy design.net> wrote in message
    news:evy6BkuhDH A.1740@tk2msftn gp13.phx.gbl...[color=blue]
    > Hi guys,
    >
    > Anyone knows about how to save a picture from a html page to the hard disk
    > either in C# or VB.NET? What I have done so far is the following and it
    > doesn't work. I got an empty image created on the HDD.
    >
    > _webRequest =
    >[/color]
    CType(Net.WebRe quest.Create("h ttp://wdz.whereis.com .au/gns?user=demo&p ass=de[color=blue]
    >[/color]
    mo&geolang=en&f unction=map&mod e=server_1.2&wg s84x1y1=-37.820130359563 16|144.[color=blue]
    > 98320052639244& radius=800&widt h=400&height=40 0&format=gif&no url=1),
    > Net.HttpWebRequ est)
    >
    > _webResponse = CType(_webReque st.GetResponse( ),[/color]
    Net.HttpWebResp onse)[color=blue]
    > _stream = _webResponse.Ge tResponseStream
    >
    > Dim inBuf(100000) As Byte
    > Dim bytesToRead As Integer = CInt(inBuf.Leng th)
    > Dim bytesRead As Integer = 0
    >
    > While bytesToRead > 0
    > Dim n As Integer = _stream.Read(in Buf, bytesRead, bytesToRead)
    > If n = 0 Then
    > Exit While
    > End If
    > bytesRead += n
    > bytesToRead -= n
    > End While
    >
    > If Not IO.Directory.Ex ists(Me.GiveFil ePath) = True Then
    > IO.Directory.Cr eateDirectory(M e.GiveFilePath)
    > End If
    >
    > _fileStream = New IO.FileStream(M e.GiveFilePath & "\map.gif",
    > IO.FileMode.Ope nOrCreate, IO.FileAccess.W rite)
    > _fileStream.Wri te(inBuf, 0, bytesRead)
    >
    > _webResponse.Cl ose()
    > _fileStream.Clo se()
    >
    >
    > Thanks
    >
    > Laszlo
    >
    >[/color]

    Comment

    Working...