xml| Data | download
A few days ago in the use of ASP to develop PDM system. System development involves some data import and export procedures! I started to try it myself. A CSV-formatted import exporter. The effect is also good, but still not satisfied, because some data is not satisfied with CSV, such as the database contains multiple "," No way. Help some reference books, hehe, finally found a more convenient way, is to import the database with XML! Now put the code out, and share with you!
A total of three files are required:
Conn.asp for database Connections!
download.asp download page
Data_to_xml.asp Transfer data page
Filename:
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"
' Use SQL to find out what data to export!
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
' If your server is powered by an older version of Access, use the following connection method
' connstr= ' Driver={microsoft Access driver (*.mdb)};d bq= "& Db_path
Conn. Open ConnStr
%>
Download.asp
------------------------------------------------------
<%
'''''''''''''''''''''''''''''''''''''''''''
' Document function: Download components
' Creation time: 2005-8-19
' Modify the situation:
'''''''''''''''''''''''''''''''''''''''''''
Const FORREADING=1
Const TRISTATETRUE=-1
Const FILE_TRANSFER_SIZE=16384
Response. Buffer=true
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' For file downloads!
' F_path: The absolute path to the file, F_filename: the filename to save
'''''''''''''''''''''''''''''''''''''''''''''''
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 as 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
%>