Using response attribute in ASP (turn)

Source: Internet
Author: User
Using response attribute skillfully in response ASP

----I am in the ASP for a unit to create a Web page, encountered such a problem, the unit before the MIS system will
Some Word files are stored in the database as a stream of bytes, and now the user asks me to use ASP to put these wor
d file data is removed from the database and displayed in the Web page. At first I naturally thought of creating on the server
Create a temporary file, and then add a link to the temporary file in the Web page, but this method will be large
Large increase in server burden not to say, and how to ensure that temporary files used by specific clients on the service
Files that are not overwritten by other clients, how to delete files after they are passed to the user
It is difficult to solve the problem in practice. So is there a better way?

----for this I carefully looked at the ASP's reference books, found response object has a name Contentt
A ype property that defines the MIME type that the server sends to the client's content. MIME Full name Multipurpos
e Internet Mail Extensions, the Multipurpose Internet Mail extension. We know that in the Web page
In programming we sometimes point hyperlinks to a Word or Excel file, and when the user clicks on the link, browse
Device automatically invokes the corresponding method to open the file. The reason we can do this is because the user machine
When you install Office, the corresponding MIME resource type is registered in the browser. For example, the MIME class for Word files
The type is Application/msword (the former is a MIME type, the latter is a mime subclass), and the Excel file's M
The IME resource type is application/msexcel. In fact, all the resources that the browser can handle are
There is a corresponding MIME resource type, such as the MIME type of the HTML file is text/html,jpg file mi
The Me type is image/jpg. In the interaction with the server, the browser is based on the MIME class of the accepted data
Type to determine what kind of processing to do, HTML, JPG and other file browser directly to open it, to the WOR
D, Excel and other browsers themselves can not open the file to invoke the appropriate method to open. For unmarked MIME classes
Type of file, the browser guesses its type based on its extension and file contents. If the browser cannot guess
, it is used as a application/octet-stream. To learn about the MIME types of various files, in the WI
N98 My Computer-> view-> Folder Options-> file type.

----So I brainwave, thinking that in ASP you can first take Word data out of the word stream, and then
Mark its Conntenttype property as Application/msword, and then send it to the client, the customer
When the machine receives this resource, it automatically invokes word on the client, depending on its MIME type (of course, the prerequisite
The client has word on it, otherwise it will be used as an unrecognized resource, prompting the user to save
, instead of opening it) to open it. The test results are very good, the method is simple and fast, and in IE
5 browsers use inline (similar to OLE Way) to open, better results. The following is the program content.


----Suppose the table name Tab_word, there are two fields in the table, one is an integral type, the name ID, which is used as the Word data
Unique identification, another blob type, named Worddata, which holds word data. Now to display on the page
The contents of the Word file with ID equal to 1, the ASP program is as follows:

<%
' Conn-database connection created
' RS--result set
rs = Conn.execute ("Select
Worddata from Tab_word where id = 1 ")
Response.ContentType = "Application/msword"
Response.writebinary (RS ("Worddata"))
' Note that the data in the result set is sent directly with writebinary, not with variables
' Receive this data, or the system will complain
% >



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.