<Script runat="server">
Private Sub btnDownFile_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim strFileName as String = "中国.xls" '取得下载文件
processFiles(strFileName)
End Sub
Sub processFiles( strGetFile )
Dim physicalFilePath as String = (Server.MapPath(".") + "/files/" + strGetFile)
Dim stream As System.IO.FileStream = Nothing
Try
stream = New System.IO.FileStream(physicalFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read) 
Dim bufSize As Integer = CType(stream.Length, Integer)
Dim buf(bufSize) As Byte
Dim bytesRead As Integer = stream.Read(buf, 0, bufSize)
HttpContext.Current.Response.ContentType = "application/octet-stream" 
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(System.IO.Path.GetFileName(physicalFilePath)))
HttpContext.Current.Response.OutputStream.Write(buf, 0, bytesRead)
HttpContext.Current.Response.End
Finally
stream.Close
End Try
End Sub
</Script>

<Form runat="server">
<asp:Button id="btnDown" Text="下载" OnClick="btnDownFile_Click" runat="server"/>
</Form>说明:1.打开时,可调用适合软件打开.
2.支持中文文件名保存.

浙公网安备 33010602011771号