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