1

I have a rendered HTML page that I am exporting to MS Word and downloading on a button click.

Here is the code snippet in the button click.

` Me.EnableViewState = False
    Response.ContentType = "application/vnd.ms-word"
    Response.AddHeader("Content-Disposition", "attachments;filename=XXXXXXX.doc")
    Response.Buffer = True
    Response.BufferOutput = True`

The functionality works perfectly well in Firefox & IE when I checked in system testing environment (locally). However when it was moved on to the hosting server (production environment) the functionality is not working in IE but is still working perfectly in Firefox.

I am not sure on where to check for the exact issue. Could it be a caching related problem?

In IE it is just not opening the download window which we will obtain when the rendered HTML content type is changed and the response stream is flushed. No exception is thrown.

I received the following response header:

HTTP/1.0 200 OK
Cache-Control: private 
Content-Length: 15189 
Content-Type: application/vnd.ms-word; 
charset=utf-8 Server: Microsoft-IIS/7.5 X-AspNet-Version: 2.0.50727 
Content-Disposition: attachments;filename=NewAccountForm.doc X-Powered-By: ASP.NET 
Date: Fri, 18 Mar 2011 10:18:07 GMT X-Cache: MISS from Gateway X-Cache-Lookup: MISS from Gateway:808 Via: 1.0 Gateway (squid/3.0.STABLE10) Proxy-Connection: keep-alive
moberley
  • 365
  • 4
  • 12
balu
  • 322
  • 4
  • 13
  • Do you use the same browser on the same machine when in the testing environment as you do in the production environment? There are several Microsoft KB atricles related to this for various versions of IE, so the browser makes a difference. http://www.bing.com/search?q=content-disposition+file+dialog+not+showing&form=QBRE&qs=n&sk= – David Mar 18 '11 at 14:28
  • And one other thought. Your ContentType looks wrong. I've seen "vnd." before an Excedl content-type, but not word. This list (not official, but pretty comprehensive): http://www.utoronto.ca/webdocs/HTMLdocs/Book/Book-3ed/appb/mimetype.html shows it with Excel and not Word as well. Try changing it to "Content-Type: application/msword" – David Mar 18 '11 at 14:41

2 Answers2

1

Is your hosted environment adding http headers? IIS could easily be configured to add headers that are messing up what you want to send out. It's actually quite common, and could be the issue. You'll need to determine this for sure, so here's a suggestion for investigating:

Try using a WebClient class and look at the Response headers.

Edit - updated

I just noticed - did you remember to put

Response.Clear();

before adding headers? It may not be the hosting environment at all. However, given that it works locally and not at your hosting environment, and assming that it is the same code, it still looks to me like something is different about the hosted environment, and the most logical option would be the headers.

David
  • 72,686
  • 18
  • 132
  • 173
  • @David - would that cause it to work in FX and not IE? Just curious. – Saif Khan Mar 17 '11 at 17:28
  • Possibly. You can never tell for sure, since they are different applications, regardless of how similar they are. It's definitely NOT true that what works in one browser works in another. We have issues here where Office 2010 docs can't be rendered in one browser when linked to from a web page, but can in others. It's a known issue - I'll find a link to support that, but it's definitely possible that it's the headers, and worth trying the troubleshooting I suggested. – David Mar 17 '11 at 17:37
  • See this thread for the example with Office 2010 files: http://forums.techarena.in/ms-office-support/815601.htm – David Mar 17 '11 at 17:39
  • I have inspected for the response headers using Fiddler as i don't have the liberty on working in the production system:Added below is the response header.HTTP/1.0 200 OK Cache-Control: private Content-Length: 15189 Content-Type: application/vnd.ms-word; charset=utf-8 Server: Microsoft-IIS/7.5 X-AspNet-Version: 2.0.50727 Content-Disposition: attachments;filename=NewAccountForm.doc X-Powered-By: ASP.NET Date: Fri, 18 Mar 2011 10:18:07 GMT X-Cache: MISS from Gateway X-Cache-Lookup: MISS from Gateway:808 Via: 1.0 Gateway (squid/3.0.STABLE10) Proxy-Connection: keep-alive – balu Mar 18 '11 at 10:26
  • I don't see anything in the headers that would be causing an issue. Apparently, this is the wrong answer, but you've at least eliminated a possibility. Sorry. – David Mar 18 '11 at 14:30
  • You don't need to be apologetic, actually you are helping me.Thank you for that. :) – balu Mar 18 '11 at 16:18
0

I set Response.Charset = "" and always do Response.Flush(), Response.End(), and Response.Close() after I export the HTML.

NoAlias
  • 9,218
  • 2
  • 27
  • 46