Help with translating straight VB.net code to ASP.NET using VB RRS feed

  • Question

  • User-1728878066 posted
    <color="#6633cc">Edited by SomeNewKid. Please post code between </color><color="#000000"><</color>code><color="#6633cc"> and </color><color="#000000"><</color>/code><color="#6633cc"> tags.</color>
    Greetings, The following code works fine in a Windows app written in VB.Net, however it chokes in ASP.net written in VB: Function GetImageFromURL(ByVal url As String) As Byte() Dim wr As HttpWebRequest = _ DirectCast(WebRequest.Create(url), HttpWebRequest) Dim wresponse As HttpWebResponse = _ DirectCast(wr.GetResponse, HttpWebResponse) Dim responseStream As Stream = wresponse.GetResponseStream Dim br As BinaryReader = New BinaryReader(responseStream) Dim bytesize As Long = wresponse.ContentLength Return br.ReadBytes(bytesize) End Function Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim img As New Bitmap( _ Dim img As New Bitmap( _ New IO.MemoryStream( _ GetImageFromURL( _ "http://yada.com/test.bmp") _ )) img.save("c:\file.bmp") End Sub It seems to choke on the following: Dim img As New Bitmap( _ New IO.MemoryStream( _ GetImageFromURL( _ "http://yada.com/test.bmp") _ )) with the error of: [ArugumentExecption: Invalid parameters used.] System.Drawing.Bitmap..ctor(Stream stream) Any suggestions? Thanks
    Wednesday, February 23, 2005 12:23 PM

All replies

  • User-1029435529 posted
    Did you re-type the code here on the forums? I ask because there is an obvious error in that you have repeated a line: Dim img As New Bitmap( _ Dim img As New Bitmap( _ Is that just a re-typing error, or is that in your code too?
    Wednesday, February 23, 2005 12:42 PM
  • User-1728878066 posted
    SomeNewKid, That was just a typo with the my post and not with my actual code. Cheers
    Wednesday, February 23, 2005 1:00 PM
  • User-1029435529 posted
    I just created a test page using your code, and it worked fine. Rather than the dummy yada.com/text.bmp address, are you able to supply a real address that you're trying to use?
    Wednesday, February 23, 2005 1:36 PM