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