Edit the document online and save it to the background database

Source: Internet
Author: User
Tags implement save file
Background | data | database | Edit the document online and save it to the background database
--------------------------------------------------------------------------------
Http://www.standsoft.com (2004.1.14) Article Source: Smart Island Software



Online Demo http://www.oapro.com/ostarocx/sample/savefilepro/default.asp
Source Code Http://www.oapro.com/ostarocx/download/OStarOCX_savefile.rar

Overview
This article explains an example of using the Office Star Control to edit the file online and save it to the back-end database, using this method without selecting a file step, you can realize the effect of clicking on the save file under the Web environment in a similar stand-alone environment.

Introduction

In order to obtain the upload function in the HTML webpage, we can use the form in the following format in the client:

<form name= "MyForm"
action= "Targeturl.asp"
Enctype= "Multipart/form-data"
Method= "POST" >
<input type= "File" name= "MyFile" >
<input type= "Submit" value= "Upload File" >
</FORM>

This scenario has many limitations on both the client and server side. First, we must use the Post method, because the Get method cannot process such form data. Also, there is no way to raise a post action without using the form. Once the data is sent to the form handler, the browser will load the handler as a new page, and the user will see a page conversion process that is not pleasing to the person.

The uploading scheme in the Office Star control

You need to follow these steps:

Client:

Save the document edited by the Office Star Control to a local
To send a saved temporary document to a Web server using the HTTP protocol

Server side:

Read the uploaded binary document from the request object
Reads the binary data and stores it in a BLOB field in the database.

With Office star controls you can implement word-and-text blending and word processing in a web environment, but how do you save the edited document to the server side? There seems to be nothing new in the above plan. As stated in the preface, the value of the file control is read-only, and there must be a process of selecting the document manually clicking the Upload button. Is that right? First, we introduce the two Office star Control interface methods:

1. Savetotempfile (str filename)

Saves the document currently edited with the Office Star Control to local form a temporary file with the filename file name of the temporary file. The method returns a parameter that represents the absolute path of the temporary file. Example: Savetotempfile ("Abc.ost")

2. UploadFile (str filepath,str operatorfile)

Uploads the locally specified file to the server side, with the parameter filepath as the absolute path to the local file to be uploaded, Operatorfile for the file name that the server side uses to receive the uploaded file stream. The method returns a parameter that prompts for success during the operation. Example: UploadFile ("C:\abc.ost", "http://www.oapro.com/save.asp")

See here, I believe you already understand, Office Star Control has provided an interface method to automatically upload the specified file. The complete code for the client is given below:

<script language= "VBScript" >
Public Sub Mnufilesave_click ()
Dim Str,strret

' Generate temporary files
Str=ostar.savetotempfile ("Abc.ost")

' Upload a temporary file
Strret=ostar.uploadfile (str, "http://www.oapro.com/save.asp")

' Upload success or not prompt
Alert (strret)
End Sub
</script>

The above page Ostar the name of the action object for the Office Star Control on the page. The following code is how the server side handles the upload file and saves it to the database:

<%
' Define variables and objects
Dim sql
Dim rs
Dim upfile
Dim conn
Dim connstr
Dim db

' Save the database name of the uploaded file
db= "Db.mdb"

' Get uploaded binary data
Upfile=request.binaryread (Request.TotalBytes)

' Establish a database connection
Set conn = Server.CreateObject ("ADODB. Connection ")
Connstr= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath ("&db&")
Conn. Open ConnStr
Sql= "Select Upfile from ostarreptemplate where (ID is null)"
Rs.Open sql,conn,1,3
Rs.addnew

' Add uploaded binary content into the database
RS ("Upfile"). AppendChunk Upfile
Rs.update

' Destroy the database connection object
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing

' Return storage information
Response.Write "Upload successful!"
%>

The above server-side code does not consider whether to save the first time, if so, then create a new record in the database to save the uploaded file, if not the first time, you should modify the previously saved records.

Benefits of using this method

does not cause page conversions.
No private components are required.

This program is written in plain script and can be easily inserted into other code without the need for any matching HTML objects. You can also implement this logic in any language that supports COM standards.



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.