In the OA system, you usually need to download the template and perform data operations on it.
In this process, we certainly do not want customers to control it.
We hope to use the web page to return JavaScript or vbscept to create a document for the customer.
In any case, you need to use "quiet" to download a template file and obtain the object of this template file.
How to do?
1. First, we use the XML object on the server to create an XML that contains the binary data of the file.
2. We send a webpage to the client to read XML and convert it to an existing client file,
3. Obtain the client file object and perform corresponding operations on it.
We will not talk about step 1.
1. How is it done?
<%
Getfilebyfilename ("regular assessment form .doc ")
''===================================================== ======================================
Function getfilebyfilename (docfilename)
''Ado-Stream Object
Dim ado_stream
Set ado_stream = server. Createobject ("ADODB. Stream ")
''1 = adtypebinary
Ado_stream.type = 1
Ado_stream.open ()
Ado_stream.loadfromfile server. mappath (docfilename)
''=
Set xml_dom = server. Createobject ("msxml2.domdocument ")
Xml_dom.loadxml ("<? XML version = '1. 0'?> <Root/> ")
''Specifies the Data Type
Xml_dom.documentelement.setattribute "xmlns: DT", "urn: Schemas-Microsoft-com: datatypes"
''Create a new node and set it as a binary data node
Set filedata_node = xml_dom.createelement ("filedata ")
Filedata_node.datatype = "bin. base64"
''-1 = adreadall
Filedata_node.nodetypedvalue = ado_stream.read (-1)
Ado_stream.close ()
Xml_dom.documentelement.appendchild (filedata_node)
Response. Write xml_dom.xml
End Function
''===================================================== ======================================
%>
Use localhost/your virtual directory/fileservice. asp
Let's take a look:
<? XML version = "1.0"?>
-<Root xmlns: dt = "urn: Schemas-Microsoft-com: datatypes">
<Filedata DT: dt = "bin. base64"> 0m8r4kgxgueaaaaaaaaaaaaaaaaaaaaapgadap7/cqagaaaaaaaaaaaaaaabaaaaqwaaaaaa commandid </filedata>
</Root>
I have modified filedata.
Then let's finish 2.
'Create an xmldom object from the request object
Set xml_dom = Createobject ("msxml2.domdocument ")
Xml_dom.load "http: // 172.16.1.249/applysheet/asp/template/fileservice. asp"
Msgbox xml_dom.text
'Read the node that contains binary data
Set xml_file1 = xml_dom.selectsinglenode ("// root/filedata ")
If isnull (xml_file1) then
Msgbox "null"
Else
Msgbox xml_file1.text
End if
'Open the stream object and store the data in it.
Ado_stream.type = 1' 1 = adtypebinary
Ado_stream.open ()
Ado_stream.write xml_file1.nodetypedvalue
'File storage disks'
'2 = adsavecreateoverwrite
Ado_stream.savetofile "C: \ temp.doc", 2
Ado_stream.close ()
'Destroy object
Set ado_stream = nothing
Set xml_dom = nothing
Easy?
Modify the script and insert it into an ASP page. Then, you can download the template file to your machine.