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

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'

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值