How to display Word file contents in a browser Web page

Source: Internet
Author: User

How to display Word file contents in a browser Web page

Read the Word file into byte[], and then Response.OutputStream.Write (bytes) to the client.

In the Page_Load event, write:

FileStream fs = new FileStream ("C:\\1.doc", FileMode.Open, FileAccess.Read); FileStream fs = new FileStream (Server.MapPath ("Files\\1.doc"), FileMode.Open, FileAccess.Read);

byte[] bytes = new byte[(int) fs. Length];

Fs. Read (bytes, 0, bytes. Length);

Fs. Close ();

Response.ContentType = "Application/msword";

Response.outputstream (bytes);

Response.OutputStream.Write (bytes,0, bytes. Length);

Response.End ();

To display the contents of a. txt file in a Web page:

Can be displayed directly, if you want to put in the table, you can <iframe src= "XXX.txt" ></iframe>

Word files can also follow this.

In order to correctly handle formatting such as word, you need to set the file type in the HTML file, for example:

<meta http-equiv= "Content-type" content= "Application/msword" >

There are other file types that are often set:

Application/msword Microsoft Word Document

Application/pdf PDF Document

application/wordperfect6.0 WordPerfect 6.0 Document

Application/zip Zip archive

Audio/x-wav WAV Audio format

Audio/midi MIDI Audio format

Audio/x-pn-realaudio RealAudio

Image/gif GIF image format

Image/jpeg JPEG image format

Image/png PNG image format

Text/html HTML Document

Text/plain Plain Text

VIDEO/MPEG MPEG Video Format

Video/quicktime QuickTime Video Format

Video/x-msvideo AVI Video Format

The article originates from Yixian network http://www.ynpxrz.com/n765461c2023.aspx

There is one more, do reference

Response.setcontenttype ("application/vnd.ms-excel");
File file =new file ("D:/test.xls");
FileInputStream in=new fileinputstream (file);
Byte[] Buffer=new byte[in.available ()];
In.read (buffer);
Response.getoutputstream (). write (buffer);
Response.getoutputstream (). Flush ();

How to display Word file contents in a browser Web page

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.