Forcing a save of a downloaded document

T

teeBull

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
 
G

Guest

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"
 
T

teeBull

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
 
G

Guest

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.
 
T

teeBull

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.
 

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

Staff online

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top