Convert data to XML file download with ASP

Source: Internet
Author: User
Tags flush include access
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
%>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.