Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

 

   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

Codeless

...it just goes on and on.

  • 2 weeks later...
Posted

That is exactly what I'm 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?

 

  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?

Codeless

...it just goes on and on.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...