FileName为你导出的txt文件的全路径
FileInfo
file
=
new
FileInfo(FileName)//用于获得文件信息
Response.Clear()//清空输出
Response.Charset
=
"GB2312"//设定编码
Response.ContentEncoding
=
System.Text.Encoding.UTF8
//
添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader("Content-Disposition",
"attachment
filename="
+
Server.UrlEncode(FileName))
//
添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length",
file.Length.ToString())
//
指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType
=
"application/ms-txt"
//
把文件流发送到客户端
Response.WriteFile(file.FullName)
<!--#include file="inc/conn.asp"--><%
dim rs,sql,filename,fso,myfile,x
Set fso = server.CreateObject("scripting.filesystemobject")
filename = Server.MapPath("download.txt")
if fso.FileExists(filename) then
fso.DeleteFile(filename)
end if
'--创建txt文件
set myfile = fso.CreateTextFile(filename,true)
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "select * from userfile"
rs.Open sql,conn,1,1
if rs.EOF and rs.BOF then
response.write "无数据"
else
dim strLine,responsestr
strLine=""
'--将表的列名先写入txt
For each x in rs.fields
strLine = strLine &x.name &chr(9)
Next
myfile.writeline strLine
Do while Not rs.EOF
strLine=""
for each x in rs.Fields
strLine = strLine &x.value &chr(9)
next
'--将表的数据写入txt
myfile.writeline strLine
rs.MoveNext
loop
end if
rs.Close
set rs = nothing
Response.ContentType="application/x-msdownload"
Response.Redirect "download.txt"
%>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)