By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,105 Members | 1,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,105 IT Pros & Developers. It's quick & easy.

Forcing a save of a downloaded document

P: n/a
Hi all,

We'd like to take advantage of code we already have for transforming
XML into HTML (using XSLT) for our users to save the HTML as an MS Word
document locally. I've dug around and found the following code to
include in the code behind:

Response.ContentType = "application/vnd.ms-word"
Response.AddHeader("Content-Disposition",
"inline;filename=someFile.doc")

As it is, the user gets the document and can open, save, or cancel with
the file dialog box. If s/he opens the document and then tries to
save, the default setting is to save with an HTM extension, which is
what we need to avoid. We want to ensure that the document gets saved
as a DOC file so I'd like to know if there's a way to force the user to
save the file locally (with a DOC extension) before viewing the
document. Any suggestions?

Thanks,

Anthony

Jun 26 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
> As it is, the user gets the document and can open, save, or cancel with
the file dialog box. If s/he opens the document and then tries to
save, the default setting is to save with an HTM extension, which is
what we need to avoid. We want to ensure that the document gets saved
as a DOC file so I'd like to know if there's a way to force the user to
save the file locally (with a DOC extension) before viewing the
document. Any suggestions?


Change your content type to application/octet-stream:

Response.ContentType = "application/octet-stream"
Jun 26 '06 #2

P: n/a
Thanks for trying but that didn't work.

Let me further clarify. The content is being dynamically generated as
XML and then transformed using XSLT into HTML which is being dumped
into the Response stream using Response.Write() when users click on a
link.

At that time, they're prompted to either "Open," "Save As," or "Cancel"
via the file dialog box. If they select "Save As," the content is
saved into a DOC file without a problem. If the user selects "Open,"
views the file, and then saves, the default extension is HTM.

We don't want to have to rely on users remembering to change the
extension when they save so either we need to:
a) disable the "Open" button on the file dialog, forcing them to
save before viewing OR
b) figure out a way to force word to save the content as a DOC file.

Suggestions are still welcome.

Anthony

Jun 26 '06 #3

P: n/a
> We don't want to have to rely on users remembering to change the
extension when they save so either we need to:
a) disable the "Open" button on the file dialog, forcing them to
save before viewing OR
b) figure out a way to force word to save the content as a DOC file.


OK, I see what you mean now.

I can't be certain, but I presume there is no way of specifying this, as
it's down to the browser what it wants to do with the file. What most sites
do is to provide a description of what the user should do, with small
screenshots, e.g:

1) Click 'Download file' below
2) When you receive a prompt such as the one below, select 'Save As...', do
not select 'Open'
3) Choose a location on your computer to save the file to
4) Browse to the location in 'My Computer' and open the file.
Jun 26 '06 #4

P: n/a
> it's down to the browser what it wants to do with the file

I had figured that the setting were local and there'd be no way to
determine those in the HTTP headers but I'd hoped to hear otherwise ;-)

Thanks for the input.

Jun 27 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.