總共需要三個文件:
conn.ASP用於數據庫連接!
download.ASP下載頁面
data_to_XML.ASP轉數據頁面
文件名:
data_to_XML.ASP
-----------------------------------------------
<!--#include file="download.ASP"-->
<!--#include file="conn.ASP"-->
<%
set rs=server.CreateObject("adodb.recordset")
set fso=server.CreateObject("Scripting.FileSystemObject")
'''''''''''''''''''''''''''''''
xml_filepath=root_path & "\loadfile\file_class.XML"
'用SQL查出要導出的數據!
sql="select * from file_class"
rs.open sql,conn,1,3
if fso.fileexists(XML_filepath) then
fso.deletefile XML_filepath
end if
rs.save XML_filepath,1
''----------------------------------------------
call transferfile(xml_filepath,"file_class.XML")
response.end
%>
conn.ASP
-----------------------------------------------
<%
db_path=root_path & "\data\syste_@k#ksks.asa"
'response.write db_path
'response.end
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & db_path
'如果你的服務器采用較老版本Access驅動,請用下面連接方法
'connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & db_path
conn.Open connstr
%>
download.ASP
------------------------------------------------------
<%
'''''''''''''''''''''''''''''''''''''''''''
'' 文檔作用:下載組件
'' 創建時間:2005-8-19
'' 修改情況:
'''''''''''''''''''''''''''''''''''''''''''
const forreading=1
const tristatetrue=-1
const file_transfer_size=16384
response.Buffer=true
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' 用於文件下載!
'' f_path:文件的絕對路徑,f_filename:要保存的文件名
'''''''''''''''''''''''''''''''''''''''''''''''
function transferfile(f_path,f_filename)
dim path,mimetype,filename
dim objfilesystem,objfile,obJStream
dim char
dim sent
path=f_path
filename=f_filename
send=0
transferfile=true
set objfilesystem=server.CreateObject("scripting.filesystemobject")
set objfile=objfilesystem.getfile(path)
mimetype=objfile.type
set obJStream=objfile.openastextstream(forreading,tristatetrue)
response.AddHeader "content-disposition","attachment;filename=" & filename
response.AddHeader "content-length",objfile.size
do while not obJStream.atendofstream
char = obJStream.read(1)
response.BinaryWrite(char)
sent=sent+1
if(sent mod file_transfer_size)=0 then
response.Flush()
if not response.IsClIEntConnected then
transferfile=false
exit do
end if
end if
loop
response.flush
if not response.IsClIEntConnected then transferfile=false
obJStream.close
set obJStream=nothing
set objfilesystem=nothing
end function
%>