Javascript – Response.Redirect Word Document Glitch

asp.netjavascriptms-wordresponse.redirect

I come a desperate and broken man….

I'm developing a corporate intranet / search engine application. When users open a document, my ASP.NET code records the action to the Windows Event log, and then issues a "Response.Redirect" (for security/audit).

Process is:
– User clicks LinkButton "Open document My Document.doc"
– Postback occurs
– Server side code records the user opening document action to SQL + Windows Event log
– Response.Redirect navigates to specified document

Works fine for everything except Word documents. EG, PDF, JPG is fine. Using Word 2007.

The code is:

Response.Redirect("http://intranet/wcm/mydocument.doc");

When I call this code, and an existing Word instance is open, Word just 'flashes' any documents that are already open in the task bar. When the user clicks the annoying flashing Word instance on the taskbar, it instantly opens the document it was supposed to. Arr!

WHY!? It's driving me nuts.

*****Sidenote:*
Internet Explorer ignores clientside javascript 'window.open' if a Word document is specified. So I can't use that.***

Best Answer

It appears as though the decision process is up to Microsoft Word after the document is downloaded. At that point it's hands off for the browser because its job is done. You might want to change the Mime Type of the download so Word/IE doesn't immediately recognize it, and the user is forced to save it to disk (and this might be more in line with how other browsers would handle it)....

Edit: Straight from Microsoft, info about how to force a download for a known mime type. If you choose this way, the Content-Disposition header will need to be programmatically set. You will need to customize the download process by replacing Response.Redirect with something else like an ASPX page that modifies its headers as desired for the download (esp. Content-Disposition) and then programmatically reads the file from disk and writes it to the Response output stream. Microsoft has many good code samples in its MSDN docs under the Write methods of the HttpResponse class; you will likely find one or a combination of them that fit.

Related Topic