Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi
I have to download file in another page ,i mean if click link button in default.aspx page ,open download.aspx page in page load i call the function for download
VB
Private Sub DownloadFile(ByVal fullpath As String, ByVal forceDownload As Boolean)
       '    Dim path As Path
       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", ".pdf"
               type = "Application/pdf"
           Case ".zip", ".ZIP"
               type = "Application/zip"
           Case ".zip", ".csv"
               type = "text/csv"
           Case Else
               type = "text/plain"
       End Select


       ''Dim req As New WebClient
       ''Dim response As HttpResponse
       ''response = HttpContext.Current.Response
       ''response.Clear()
       ''response.ClearContent()
       ''response.ClearHeaders()
       ''response.Buffer = True
       ''response.AddHeader("Content-Disposition", "attachment; filename=" + name)
       ''response.ContentType = "application/octet-stream"
       ' ''response.BinaryWrite(Buffer)
       ''response.Flush()
       ''response.End()

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

       Response.WriteFile(fullpath)
       Response.Flush()
       Response.End()
   End Sub


The above code is download and close page,it will work in ie9,mozila and chrome but in IE8 not work.i use comment code also but not work.

pls reply asap
Regards
Aravind
Posted
Comments
ZurdoDev 22-Jul-13 13:24pm    
What does happen?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900