Click here to Skip to main content
15,891,529 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Call Intemediary page while loading page Pin
Prachi Mhatre28-May-11 9:53
Prachi Mhatre28-May-11 9:53 
GeneralRe: Call Intemediary page while loading page Pin
AspDotNetDev28-May-11 10:43
protectorAspDotNetDev28-May-11 10:43 
GeneralRe: Call Intemediary page while loading page Pin
Prachi Mhatre28-May-11 12:14
Prachi Mhatre28-May-11 12:14 
GeneralRe: Call Intemediary page while loading page Pin
AspDotNetDev28-May-11 12:16
protectorAspDotNetDev28-May-11 12:16 
QuestionDocuments in SQL Server database Pin
Aptiva Dave27-May-11 7:51
Aptiva Dave27-May-11 7:51 
AnswerRe: Documents in SQL Server database Pin
Not Active27-May-11 8:10
mentorNot Active27-May-11 8:10 
GeneralRe: Documents in SQL Server database Pin
Aptiva Dave27-May-11 8:25
Aptiva Dave27-May-11 8:25 
GeneralRe: Documents in SQL Server database Pin
Aptiva Dave27-May-11 9:57
Aptiva Dave27-May-11 9:57 
So I tried implementing the same logic used to get images from the database, but instead of displaying the file my browser wants to open a file called DisplayResume.ashx.
Here is the code I used in my event Handler:
<%@ WebHandler Language="VB" Class="displayResume" %>

Imports System
Imports System.Web
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports util

Public Class displayResume : Implements IHttpHandler
    
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        Dim appID As Integer
        Dim mimeType As String
        If Not context.Request.QueryString("ID") Is Nothing Then
            'place ID in the the appID variable
            appID = context.Request.QueryString("ID").ToString
            'get the mimetype for the file from table
            mimeType = getMimeType(appID.ToString)
            If Not mimeType Is Nothing Then
                context.Response.ContentType = mimeType
                Dim strm As Stream = getResume(appID)
                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
            Else
                Throw New ArgumentException("Can't retrieve MIME Type")
            End If
        Else
            Throw New ArgumentException("No Parameter specified")
        End If
    End Sub
    
    ''' <summary>
    ''' Gets the mime type for the resume from the database
    ''' </summary>
    ''' <param name="appID">appID for the resume we are looking for</param>
    ''' <returns>mimetype string</returns>
    ''' <remarks></remarks>
    Public Function getMimeType(ByVal appID As String) As String
        Dim rdrMime As SqlDataReader = GetReader("select mimeType from resumes where appID =" & appID)
        Dim mimetype As String = Nothing
        Try
            While rdrMime.Read
                mimetype = rdrMime("mimeType").ToString
            End While
        Catch ex As Exception
            Return Nothing
        Finally
            rdrMime.Close()
        End Try
        
        Return mimetype
    End Function
    
    ''' <summary>
    ''' gets the binary format of the file from the database
    ''' </summary>
    ''' <param name="ID">appID that is pointing to the resume file</param>
    ''' <returns>binary representation of the resume file</returns>
    ''' <remarks></remarks>
    Public Function getResume(ByVal ID As Integer) As Stream
        Dim strConnection As String = ConfigurationManager.ConnectionStrings("connectionString").ToString
        Dim conn As SqlConnection = New SqlConnection(strConnection)
        Dim sql As String = "Select theFile from Resumes where appID = " & ID
        Dim cmd As SqlCommand = New SqlCommand(sql, conn)
        Try
            conn.Open()
            Dim file As Object = cmd.ExecuteScalar
            Return New MemoryStream(CType(file, 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

GeneralRe: Documents in SQL Server database Pin
Not Active27-May-11 10:11
mentorNot Active27-May-11 10:11 
GeneralRe: Documents in SQL Server database Pin
Aptiva Dave27-May-11 10:29
Aptiva Dave27-May-11 10:29 
GeneralRe: Documents in SQL Server database Pin
Not Active27-May-11 12:08
mentorNot Active27-May-11 12:08 
GeneralRe: Documents in SQL Server database Pin
Aptiva Dave31-May-11 8:51
Aptiva Dave31-May-11 8:51 
QuestionProtect XML from outside access in asp.net Pin
Prasanta_Prince26-May-11 21:04
Prasanta_Prince26-May-11 21:04 
AnswerRe: Protect XML from outside access in asp.net Pin
AspDotNetDev26-May-11 21:47
protectorAspDotNetDev26-May-11 21:47 
GeneralRe: Protect XML from outside access in asp.net Pin
Prasanta_Prince26-May-11 22:59
Prasanta_Prince26-May-11 22:59 
QuestionSafe logout in asp.net Pin
Ranjani krishnamurthy26-May-11 18:06
Ranjani krishnamurthy26-May-11 18:06 
AnswerRe: Safe logout in asp.net Pin
Blue_Boy26-May-11 21:19
Blue_Boy26-May-11 21:19 
AnswerRe: Safe logout in asp.net Pin
Monjurul Habib27-May-11 9:04
professionalMonjurul Habib27-May-11 9:04 
QuestionSetting Environment Variables Pin
indian14326-May-11 13:01
indian14326-May-11 13:01 
AnswerRe: Setting Environment Variables Pin
R. Giskard Reventlov26-May-11 23:09
R. Giskard Reventlov26-May-11 23:09 
GeneralRe: Setting Environment Variables Pin
indian14327-May-11 5:52
indian14327-May-11 5:52 
QuestionFilter RSS Feeds by Keywords Using LINQ to XML Pin
Dominick Marciano26-May-11 12:48
professionalDominick Marciano26-May-11 12:48 
QuestionHow to call back to a VBS file or EXE from the Menu control? [modified] Pin
Jun Du26-May-11 5:36
Jun Du26-May-11 5:36 
AnswerRe: How to call back to a VBS file or EXE from the Menu control? Pin
Dalek Dave1-Jun-11 22:29
professionalDalek Dave1-Jun-11 22:29 
Questionauthenticate particular page in a directory to particular user or role Pin
Asif Rehman26-May-11 3:30
Asif Rehman26-May-11 3:30 

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.