Use Response.WriteFile to display .doc file

G

Guest

I has a question:
I can use Response.WriteFile to display images such as .jpg.
But I can not us it to display words doc file in EI by calling
Response.WriteFile("testdoc/DownloadLarge.doc").
It only shows unreadable chars.

How to use it to show the doc file on webrowser?

Thanks

David
 
K

Karl Seguin

Try setting the content type and making sure nothing else gets sent along
the way....

Response.ClearContent()
Response.ClearHeaders();
Response.ContentType = "application/msword"
Response.WriteFile(ExportPath)
Response.Flush()
Response.Close()

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 
G

Guest

Thank you very much, Karl.
It works!
Could you give some hint about my next question:
(1) Whether the ContentType msword is predefined in browser in the code:
Response.ContentType = "application/msword"
(2) If I have my own file processing application, say, fileapp, which can be
running in client side. Can I use the following code?
Response.ContentType = "application/fileapp"

Thanks

David
 
K

Karl Seguin

Take a look at:
http://ppewww.ph.gla.ac.uk/~flavell/www/content-type.html

when you set the content-type you are just sending some helpful information
to the browser for it to know how to open the file. The browser (a) might
not know what to do with the specified content type or (b) might override
your suggestion (ie, just because you sent application/msword, the browser
coudl decide to open the file up in notepad)...

To get your own content type to work in a browser, users must configure
their browsers to recognize the content type and associate with the
appropriate action (ie, open your application). There are certainly ways
to do this, but I don't have the slightest idea how :)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 
G

Guest

Thanks.
I will try to figure it out.


David

Karl Seguin said:
Take a look at:
http://ppewww.ph.gla.ac.uk/~flavell/www/content-type.html

when you set the content-type you are just sending some helpful information
to the browser for it to know how to open the file. The browser (a) might
not know what to do with the specified content type or (b) might override
your suggestion (ie, just because you sent application/msword, the browser
coudl decide to open the file up in notepad)...

To get your own content type to work in a browser, users must configure
their browsers to recognize the content type and associate with the
appropriate action (ie, open your application). There are certainly ways
to do this, but I don't have the slightest idea how :)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,157
Latest member
MercedesE4
Top