Asp.net檔案上傳與下載

王朝asp·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

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>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航