Asp.net檔案上傳與下載11/23

1.上傳

        Dim isize As Double
        If File1.PostedFile.ContentLength = 0 Then
            Exit Sub
        Else
            isize = Math.Round(File1.PostedFile.ContentLength / 1024, 2)
            TextBox4.Text = isize
            File1.PostedFile.SaveAs(Server.MapPath("../files/aa.txt"))
        End If

2.下載

        Dim sFilePath As String
        sFilePath = Request.QueryString("FileName").ToString()

        If Not (sFilePath = "") Then
            Dim sSeparator As String = "/"
            Dim arrSeparator As Char() = sSeparator.ToCharArray
            Dim arrPath As String()
            arrPath = sFilePath.Split(arrSeparator)
            Dim sFileName As String = arrPath(arrPath.GetUpperBound(0))
            Response.Clear()
            Response.ContentType = "application/octet-stream"
            Response.AddHeader("Content-Disposition", "attachment; filename=" + sFileName)
            Response.Flush()
            Response.WriteFile(sFilePath)
        End If

web.config:
<configuration>
  <system.web>
    <httpRuntime maxRequestLength="15360" executionTimeout="3600" />'15MB,即使VB.NET此時也要注意大小寫
  </system.web>
</configuration>

P.s.如果檔案很大,可參考:http://blog.joycode.com/saucer/archive/2004/03/16/16225.aspx

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值