我编写了以下asp代码来生成csv文件:
<%@ Language=JScript %>
<%
Response.ContentType = "text/csv";
var boCaseDetail = Server.CreateObject ("ADODB.Recordset");
var strCon = "DSN=FAS";
var adForwardOnly = 3;
var adLockReadOnly = 1;
var adCmdText = 1;
var sSqlCaseDetail = "Select objid,id_number, case2address,case_reporter2contact, case_reporter2site, x_fault_id from table_case where id_number in (" + filterFID + ") " ;
boCaseDetail.Open(sSqlCaseDetail, strCon, adForwardOnly, adLockReadOnly, adCmdText);
while(!boCaseDetail.EOF)
{
output = boCaseDetail("x_fault_id").value + " " + cstrDelim + boCaseDetail("id_number").value + cstrDelim + "\n";
Response.Write (output);
boCaseDetail.MoveNext();
}
boCaseDetail.Close();
}
%>
上面的脚本只需点击一下按钮即可生成一个asp文件。当提取的记录数小于200时,它正在创建一个asp文件。但是当记录数超过200时,不会生成任何文件。相反,数据显示在Web浏览器中。
无论记录计数如何,我都需要成功生成csv文件(而不是.asp文件)。怎么做到呢?
答案 0 :(得分:0)
尝试发送标题告诉浏览器它是一个具有给定文件名的可下载文件:
<%
Response.ContentType = "text/csv";
Response.AddHeader "Content-Disposition", "attachment; filename=YourFileName.csv"