Click here to Skip to main content
15,887,135 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Can a web application run without Web.Config Pin
Prasanta_Prince15-May-11 20:54
Prasanta_Prince15-May-11 20:54 
QuestionDynamic Grid Pin
Ramkumar_S12-May-11 15:53
Ramkumar_S12-May-11 15:53 
AnswerRe: Dynamic Grid Pin
Andy_L_J12-May-11 21:33
Andy_L_J12-May-11 21:33 
QuestionHow can my hosted asp.net website access my local machine database Pin
akosidandan12-May-11 14:53
akosidandan12-May-11 14:53 
Questionword document in ASP.Net Pin
jashimu12-May-11 10:15
jashimu12-May-11 10:15 
QuestionDatagrid performance Pin
vanikanc12-May-11 9:56
vanikanc12-May-11 9:56 
AnswerRe: Datagrid performance Pin
David Mujica13-May-11 3:14
David Mujica13-May-11 3:14 
QuestionResizing images from SQL Database Pin
Aptiva Dave12-May-11 6:20
Aptiva Dave12-May-11 6:20 
I've recently been given a task to take information out of a SQL database and display it on a site. I didn't create the database or the application that stores information on the database, but there are images stored in the database that I must display on my site. The images stored are of different sizes which I'm sure of until I pull them out using a Generic HTTP handler on my site. I've got to show thumbnails of these images so I was was wondering if I could use something that could do this dynamically in code.

The following is the handler I am using:

<%@ WebHandler Language="VB" Class="ShowImage" %>

Imports System
Imports System.Configuration
Imports System.Web
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports util
Public Class ShowImage : Implements IHttpHandler
    
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        Dim staffID As Integer
        If Not context.Request.QueryString("id") Is Nothing Then
            staffID = CInt(context.Request.QueryString("id"))
        Else
            Throw New ArgumentException("No parameter specified")
        End If
        
        context.Response.ContentType = "image/jpeg"
        Dim strm As Stream = ShowSTARImage(staffID)
        Dim buffer As Byte() = New Byte(4095) {}
        Dim byteSeq As Integer = strm.Read(buffer, 0, 4096)
        
        Do While byteSeq > 0
            context.Response.OutputStream.Write(buffer, 0, byteSeq)
            byteSeq = strm.Read(buffer, 0, 4096)
        Loop
    End Sub
 
    Public Function ShowSTARImage(ByVal staff As Integer) As Stream
        Dim strConnection As String = ConfigurationManager.ConnectionStrings("Star").ToString
        Dim conn As SqlConnection = New SqlConnection(strConnection)
        Dim sql As String = "Select picture from contactPage where userID = " & staff
        Dim cmd As SqlCommand = New SqlCommand(sql, conn)
        conn.Open()
        Dim img As Object = cmd.ExecuteScalar ()
        Try
            Return New MemoryStream(CType(img, Byte()))
        Catch ex As Exception
            Return Nothing
        Finally
            conn.Close()
            conn.Dispose()
        End Try
    End Function
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class


Right now I am displaying the image on my site with an image control which calls the handler like so:

imgContactPage.ImageUrl = "~/ShowImage.ashx?id=" & Session("selectedUser").ToString

Using this, I can have some very large images that look bad on the page as it breaks all of my other design elements.
AnswerRe: Resizing images from SQL Database Pin
AspDotNetDev12-May-11 7:22
protectorAspDotNetDev12-May-11 7:22 
GeneralRe: Resizing images from SQL Database Pin
Aptiva Dave12-May-11 8:00
Aptiva Dave12-May-11 8:00 
GeneralRe: Resizing images from SQL Database Pin
AspDotNetDev12-May-11 8:13
protectorAspDotNetDev12-May-11 8:13 
QuestionHow to get a timer in ASP.NET 2.0 w/o AJAX? Pin
Jun Du12-May-11 3:54
Jun Du12-May-11 3:54 
AnswerRe: How to get a timer in ASP.NET 2.0 w/o AJAX? Pin
Blue_Boy12-May-11 4:21
Blue_Boy12-May-11 4:21 
AnswerRe: How to get a timer in ASP.NET 2.0 w/o AJAX? Pin
AspDotNetDev12-May-11 7:04
protectorAspDotNetDev12-May-11 7:04 
Questiondelivery report and view report for mails Pin
vishnuvardhan8112-May-11 3:04
vishnuvardhan8112-May-11 3:04 
AnswerRe: delivery report and view report for mails Pin
Sandeep Mewara12-May-11 6:38
mveSandeep Mewara12-May-11 6:38 
Questionremove items from checkedlistbox using javascript Pin
vineesh v11-May-11 20:12
vineesh v11-May-11 20:12 
AnswerRe: remove items from checkedlistbox using javascript Pin
Hiren solanki11-May-11 20:40
Hiren solanki11-May-11 20:40 
AnswerRe: remove items from checkedlistbox using javascript Pin
Dalek Dave18-May-11 14:11
professionalDalek Dave18-May-11 14:11 
QuestionGridview strange question Pin
Pankaj Nikam11-May-11 6:03
professionalPankaj Nikam11-May-11 6:03 
AnswerRe: Gridview strange question Pin
Blue_Boy11-May-11 20:57
Blue_Boy11-May-11 20:57 
QuestionLink text on picture. Pin
sarja7910-May-11 18:42
sarja7910-May-11 18:42 
AnswerRe: Link text on picture. Pin
meeram39510-May-11 20:30
meeram39510-May-11 20:30 
GeneralRe: Link text on picture. Pin
sarja7910-May-11 23:14
sarja7910-May-11 23:14 
GeneralRe: Link text on picture. Pin
meeram39510-May-11 23:33
meeram39510-May-11 23:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.