Tricky problem with Responses and PageLoad

Codeless

Well-known member
Joined
Jan 24, 2003
Messages
59
Location
Great NW
I am trying to force the Open/Download dialog box. This code works, but the first time through it prompts me to save or download the actual .aspx page that I am hyperlinking to. When I choose open, then it gives me the dialog that I am looking for which is to download or open the Torus_grn.jt file. Any ideas on how I can change this so that I only get the dialog about the Torus_grn.jt file?

Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim fname As String = "c:\TORUS_GRN.jt"
        Dim forceDownload As Boolean = True
        Dim path As Path
        Dim fullpath = path.GetFullPath(fname)
        Dim name = path.GetFileName(fullpath)
        Dim ext = path.GetExtension(fullpath)
        Dim type As String = ""
 
        If Not IsDBNull(ext) Then
            ext = LCase(ext)
        End If

        Select Case ext
            Case ".htm", ".html"
                type = "text/HTML"
            Case ".txt"
                type = "text/plain"
            Case ".doc", ".rtf"
                type = "Application/msword"
            Case ".csv", ".xls"
                type = "Application/x-msexcel"
            Case ".jt"
                type = "Application/x-avwin"
            Case Else
                type = "text/plain"
        End Select

        If (forceDownload) Then
            Response.AppendHeader("content-disposition", _
            "attachment; filename=" & name)
        End If
        If type <> "" Then
            Response.ContentType = type
        End If

        Response.WriteFile(fullpath)
        Response.End()
    End Sub
 
That is exactly what Im looking for. However I when I try and run it without the database stuff (I just want to point to a file that is on the server). It fails. Can you see why?

Code:
   Private Sub GetDownload()
        Try
            Dim sFile As String = "c:\jontest.jpg" 
            Dim fn As Object
            fn = "c:\logo.bmp"
            Response.Clear()
            Response.ContentType = "image/JPG"
            Response.AppendHeader("Content-Disposition", "filename=" & fn)

            Dim oImage() As Byte = CType(fn, Byte())
            Dim oImage() As Byte = GetAttach(nID)
            Response.BinaryWrite(oImage)

        Catch
            Response.Clear()
        Finally
            Response.Flush()
            Response.Close()
        End Try

    End Sub
I think it has something to do with the object actually being a string object rather than a file object. What do you see O great one?
 
Back
Top