1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| <%@ WebHandler Language="VB" Class="ImgHandler" %>
Imports System.Collections.Generic
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.IO
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Data
Imports System
Imports System.Web
Public Class ImgHandler : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim connection As String = ConfigurationManager.ConnectionStrings("GestionConnectionString").ConnectionString
Dim con As SqlConnection = New SqlConnection(Connection)
con.Open()
Dim sql As String = "Select photo from maTable where id=@idd"
Dim cmd As SqlCommand = New SqlCommand(sql, con)
Dim idimage As SqlParameter = New SqlParameter("@idd", SqlDbType.Int, 0)
idimage.Value = context.Request.QueryString("id")
cmd.Parameters.Add(idimage)
cmd.Prepare()
Dim dr As SqlDataReader = cmd.ExecuteReader()
dr.Read()
context.Response.BinaryWrite(CType(dr("photo"), Byte()))
dr.Close()
con.Close()
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class |