Arguments Exceptions pls help T.T

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tehtarik
    New Member
    • Sep 2008
    • 1

    Arguments Exceptions pls help T.T

    Hi im currently trying to figure out the problem of a code with IHttphandler

    <%@ WebHandler Language="vb" Class="ShowImag e" %>

    Imports System
    Imports System.Configur ation
    Imports System.Web
    Imports System.IO
    Imports System.Data
    Imports System.Data.Sql Client

    Public Class ShowImage
    Implements IHttpHandler
    Public Sub ProcessRequest( ByVal context As HttpContext) Implements IHttpHandler.Pr ocessRequest
    Dim picid As Int32
    If Not context.Request .QueryString("i d") Is Nothing Then
    picid = Convert.ToInt32 (context.Reques t.QueryString(" id"))
    Else
    Throw New ArgumentExcepti on("No parameter specified")
    End If

    context.Respons e.ContentType = "image/jpeg"
    Dim strm As Stream = ShowAlbumImage( picid)
    Dim buffer As Byte() = New Byte(4095){}
    Dim byteSeq As Integer = strm.Read(buffe r, 0, 4096)

    Do While byteSeq > 0
    context.Respons e.OutputStream. Write(buffer, 0, byteSeq)
    byteSeq = strm.Read(buffe r, 0, 4096)
    Loop
    'context.Respon se.BinaryWrite( buffer);
    End Sub

    Public Function ShowAlbumImage( ByVal picid As Integer) As Stream
    Dim conn As String = ConfigurationMa nager.Connectio nStrings("album ConnString").Co nnectionString
    Dim connection As SqlConnection = New SqlConnection(c onn)
    Dim sql As String = "SELECT pic FROM Album WHERE Pic_ID = @ID"
    Dim cmd As SqlCommand = New SqlCommand(sql, connection)
    cmd.CommandType = CommandType.Tex t
    cmd.Parameters. AddWithValue("@ ID", picid)
    connection.Open ()
    Dim img As Object = cmd.ExecuteScal ar()
    Try
    Return New MemoryStream(CT ype(img, Byte()))
    Catch
    Return Nothing
    Finally
    connection.Clos e()
    End Try
    End Function

    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.Is Reusable
    Get
    Return False
    End Get
    End Property


    End Class

    i actually tired alot of other codes found in other web sites n ALL of them didnt work out properly.. (since last two weeks)
    After i debug the code above with aspx, an error poped up on the End IF below the Throw New Arguments Exception..
    mind explaining wat happening to me n how can i solve the problem??

    thx for reading : )
  • JamieHowarth0
    Recognized Expert Contributor
    • May 2007
    • 537

    #2
    Hi there,

    Firstly, welcome to Bytes.com. Please be sure to take a read through the Posting Guidelines and FAQs.

    Secondly, I've moved your thread to the .NET Forum as the ASP Forum is for classic ASP (v3.0 with VBScript/JScript)-related questions.

    Many thanks,

    medicineworker

    Comment

    Working...