Method for downloading template files in OA development: XML

Source: Internet
Author: User
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.

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.