当下载含空格的文件时,Firefox会显示不完整的文件名。
- Dim filename as String = "File Name.jpg"
- Response.Clear()
- Response.ClearHeaders()
- Response.ClearContent()
- Response.ContentType = "application/octet-stream"
- Response.AddHeader("content-disposition", "attachment; filename=" & filename )
- Response.AddHeader("Content-Length", bs.Length.ToString)
- Response.BinaryWrite(bs)
如果filename是包含空格的字符串,则下载时会出现问题。如下图
解决方法:在文件名两边加双引号,所以替换以上代码中的一句:
VB:
- Response.AddHeader("content-disposition", "attachment; filename=""" & filename & """")
JAVA
- Response.AddHeader("content-disposition", "attachment; filename=\"" + filename + "\"");
代码修改过后的下载窗口: