ADODB 流:下载文本文件问题
ADODB Stream: Download Text File Issues
我遇到的情况是当用户单击下载按钮时调用流连接。当提交下载按钮时,在 ASP 中调用一个函数,其中下载代码在文件 BD_Test1.txt
上执行。这个文本文件的内容就是 TEST 1
.
文件下载正常,但是打开它时,所有 HTML 代码都在文本文件中。
HTML代码
<html>
<head>
<title>Bulk Download Zipper</title>
<!--#include file="BD_Download.asp"-->
</head>
<body>
<center><h1>Bulk Download Zipper</h1></center>
<br><br>
<p>Please click "Download" to zip the files.</p>
<form method="post">
<br><input type = "submit" name="zipFile" value = "Download"/><br>
</form>
<br><br>
<%
If (Request.Form("zipFile") <> "") Then
Call downloadFile()
End If
%>
</body>
</html>
ASP代码
<%
Function downloadFile()
Dim download_File, download_Remove, download_Autoremove
Set download_File = Server.CreateObject("ADODB.Stream")
download_File.Type = 1
download_File.Open
download_File.LoadFromFile("E:\inetpub\wwwroot\cdc\wnyaccc_erie_niagara_trd-2\youkergav\BulkDownload\resumes\BD_Test1.txt")
Response.AddHeader "Content-Transfer-Encoding", "binary"
Response.AddHeader "Content-Description", "File Transfer"
Response.AddHeader "Content-Disposition", "attachment; filename=Resumes.txt"
Response.CharSet = "UTF-8"
Response.ContentType = "text/plain"
Response.BinaryWrite download_File.Read
download_File.Close
Set download_File = Nothing
End Function
%>
已下载文本文件的内容
<html>
<head>
<title>Bulk Download Zipper</title>
</head>
<body>
<center><h1>Bulk Download Zipper</h1></center>
<br><br>
<p>Please click "Download" to zip the files.</p>
<form method="post">
<br><input type = "submit" name="zipFile" value = "Download"/><br>
</form>
<br><br>
TEST 1
</body>
</html>
如您所见,文本文件的内容被插入到调用 downloadFile()
函数的位置。这样可以使用流连接吗?
您的 downloadFile
函数被调用 在 页面已经开始为客户端提供服务之后。 ASP 只是注入函数的结果。您将需要覆盖 POST 上的整个输出。在 GET 上输出 html,在 POST 上输出文本文件:
<%
If (Request.Form("zipFile") <> "") Then
Call downloadFile()
Else%>
<html>
<head>
<title>Bulk Download Zipper</title>
<!--#include file="BD_Download.asp"-->
</head>
<body>
<center><h1>Bulk Download Zipper</h1></center>
<br><br>
<p>Please click "Download" to zip the files.</p>
<form method="post">
<br><input type = "submit" name="zipFile" value = "Download"/><br>
</form>
<br><br>
</body>
</html>
<%
End If
%>
我遇到的情况是当用户单击下载按钮时调用流连接。当提交下载按钮时,在 ASP 中调用一个函数,其中下载代码在文件 BD_Test1.txt
上执行。这个文本文件的内容就是 TEST 1
.
文件下载正常,但是打开它时,所有 HTML 代码都在文本文件中。
HTML代码
<html>
<head>
<title>Bulk Download Zipper</title>
<!--#include file="BD_Download.asp"-->
</head>
<body>
<center><h1>Bulk Download Zipper</h1></center>
<br><br>
<p>Please click "Download" to zip the files.</p>
<form method="post">
<br><input type = "submit" name="zipFile" value = "Download"/><br>
</form>
<br><br>
<%
If (Request.Form("zipFile") <> "") Then
Call downloadFile()
End If
%>
</body>
</html>
ASP代码
<%
Function downloadFile()
Dim download_File, download_Remove, download_Autoremove
Set download_File = Server.CreateObject("ADODB.Stream")
download_File.Type = 1
download_File.Open
download_File.LoadFromFile("E:\inetpub\wwwroot\cdc\wnyaccc_erie_niagara_trd-2\youkergav\BulkDownload\resumes\BD_Test1.txt")
Response.AddHeader "Content-Transfer-Encoding", "binary"
Response.AddHeader "Content-Description", "File Transfer"
Response.AddHeader "Content-Disposition", "attachment; filename=Resumes.txt"
Response.CharSet = "UTF-8"
Response.ContentType = "text/plain"
Response.BinaryWrite download_File.Read
download_File.Close
Set download_File = Nothing
End Function
%>
已下载文本文件的内容
<html>
<head>
<title>Bulk Download Zipper</title>
</head>
<body>
<center><h1>Bulk Download Zipper</h1></center>
<br><br>
<p>Please click "Download" to zip the files.</p>
<form method="post">
<br><input type = "submit" name="zipFile" value = "Download"/><br>
</form>
<br><br>
TEST 1
</body>
</html>
如您所见,文本文件的内容被插入到调用 downloadFile()
函数的位置。这样可以使用流连接吗?
您的 downloadFile
函数被调用 在 页面已经开始为客户端提供服务之后。 ASP 只是注入函数的结果。您将需要覆盖 POST 上的整个输出。在 GET 上输出 html,在 POST 上输出文本文件:
<%
If (Request.Form("zipFile") <> "") Then
Call downloadFile()
Else%>
<html>
<head>
<title>Bulk Download Zipper</title>
<!--#include file="BD_Download.asp"-->
</head>
<body>
<center><h1>Bulk Download Zipper</h1></center>
<br><br>
<p>Please click "Download" to zip the files.</p>
<form method="post">
<br><input type = "submit" name="zipFile" value = "Download"/><br>
</form>
<br><br>
</body>
</html>
<%
End If
%>