公共模块!
Sub DownloadFile(ByVal fname As String, ByVal forceDownload As Boolean)
Dim path As Path
Dim fullpath = path.GetFullPath(fname)
Dim name = path.GetFileName(fullpath)
Dim ext = path.GetExtension(fullpath)
Dim type As String = "" If Not IsDBNull(ext) Then
ext = LCase(ext)
End If Select Case ext
Case ".htm", ".html"
type = "text/HTML"
Case ".txt"
type = "text/plain"
Case ".doc", ".rtf"
type = "Application/msword"
Case ".csv", ".xls"
type = "Application/x-msexcel"
Case Else
type = "text/plain"
End Select If (forceDownload) Then
Response.AppendHeader("content-disposition", _
"attachment; filename=" + name)
End If
If type <> "" Then
Response.ContentType = type
End If Response.WriteFile(fullpath)
Response.End()
End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
DownloadFile("c:\12.doc", True)-----------出错地方(提示:"c:\12.doc"路径不对)
End Sub
如果我换成:DownloadFile("c:\12.xls", True)格式运行正常!这是错在什么地方?
Sub DownloadFile(ByVal fname As String, ByVal forceDownload As Boolean)
Dim path As Path
Dim fullpath = path.GetFullPath(fname)
Dim name = path.GetFileName(fullpath)
Dim ext = path.GetExtension(fullpath)
Dim type As String = "" If Not IsDBNull(ext) Then
ext = LCase(ext)
End If Select Case ext
Case ".htm", ".html"
type = "text/HTML"
Case ".txt"
type = "text/plain"
Case ".doc", ".rtf"
type = "Application/msword"
Case ".csv", ".xls"
type = "Application/x-msexcel"
Case Else
type = "text/plain"
End Select If (forceDownload) Then
Response.AppendHeader("content-disposition", _
"attachment; filename=" + name)
End If
If type <> "" Then
Response.ContentType = type
End If Response.WriteFile(fullpath)
Response.End()
End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
DownloadFile("c:\12.doc", True)-----------出错地方(提示:"c:\12.doc"路径不对)
End Sub
如果我换成:DownloadFile("c:\12.xls", True)格式运行正常!这是错在什么地方?
解决方案 »
- 如何解决创建网站时 “未能找到元素“http://schemas.microsoft.com/.NetConfiguration/v2.0:configuration”的架构信息”问题
- .net程序解释
- 这个效果是怎么实现的呀?
- 求助-函数内调用存储过程中的返回值如何取得
- 服务器控件 前台调用 javascript 提示缺少) 急
- asp.net 网站的格式控制,控件布局和数据库联接的资料.....急,资料一经采用,立即加分,骗你我是你耷拉孙
- 寻找一登录页面,请大家提供一下,小弟非常感谢!!
- 请问如何写DataList控件中的表行添加双击事件和当鼠标移上移下时改变行的颜色?
- [请教]关于shtml中,相对路径的问题
- 请问那里有treeview的控件下载,最好是.msi?????----asp.net莱鸟
- >>>求助<<< 有没有关于网站整体设计方面的书?
- 大家在asp.net里将脚本都写在什么地方的呀
Sub DownloadFile(ByVal fname As String, ByVal forceDownload As Boolean)
Dim path As Path
Dim fullpath = path.GetFullPath(fname)
Dim name = path.GetFileName(fullpath)
Dim ext = path.GetExtension(fullpath)
Dim type As String = "" If Not IsDBNull(ext) Then
ext = LCase(ext)
End If Select Case ext
Case ".htm", ".html"
type = "text/HTML"
Case ".txt"
type = "text/plain"
Case ".doc", ".rtf"
type = "Application/msword"
Case ".csv", ".xls"
type = "Application/x-msexcel"
Case Else
type = "text/plain"
End Select If (forceDownload) Then
Response.AppendHeader("content-disposition", _
"attachment; filename=" + name)
End If
If type <> "" Then
Response.ContentType = type
End If Response.WriteFile(fullpath)--------------这个地方也有问题!
Response.End()
End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
DownloadFile("c:\12.doc", True)-----------出错地方(提示:"c:\12.doc"路径不对)
End Sub
如果我换成:DownloadFile("c:\12.xls", True)格式运行正常!这是错在什么地方?