从SQL取出二进制文件并下载(多种文件类型)

来源:互联网 发布:宝贝故事软件下载 编辑:程序博客网 时间:2024/05/16 15:01

1.   a.aspx页面  
      Dim name, type As String
             name = Filename.Trim(文件名)
             type = name.Substring(name.LastIndexOf(".") + 1, name.Length - name.LastIndexOf(".") - 1)
             Response.Clear()
             Select Case "." + type
                 Case ".asf"
                     ContentType = "video/x-ms-asf"
                 Case ".avi"
                     ContentType = "video/avi"
                 Case ".doc"
                     ContentType = "application/msWord"
                 Case ".zip"
                     ContentType = "application/zip"
                 Case ".xls"
                     ContentType = "application/vnd.ms-Excel"
                 Case ".gif"
                     ContentType = "image/gif"
                 Case ".jpg", "jpeg"
                     ContentType = "image/jpeg"
                 Case ".wav"
                     ContentType = "audio/wav"
                 Case ".mp3"
                     ContentType = "audio/mpeg3"
                 Case ".mpg", "mpeg"
                     ContentType = "video/mpeg"
                 Case ".rtf"
                     ContentType = "application/rtf"
                 Case ".htm", "html"
                     ContentType = "text/html"
                 Case ".Asp"
                     ContentType = "text/Asp"
                 Case Else
                     ContentType = "application/octet-stream"
             End Select
             Response.AddHeader("Content-Disposition", "attachment;filename=" + name)
             Response.BinaryWrite(从数据库取出的二进制文件)
             Response.Flush()
             Response.End()

2.   b.aspx页面  
<asp:HyperLink id="Hyperlink2" runat="server" Text='文件名' NavigateUrl='a.aspx'></asp:HyperLink>
注意:NavigateUrl='a.aspx'

 
原创粉丝点击