473,322 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Forcing a save of a downloaded document

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
4 1499
> 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
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
> 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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Poster | last post by:
I have a script, its outputs are in HTML. It displays perferctly in a browser, however when I view source, it gives me the JS scripts, but I want to view the HTML output. Is there a way I can view...
1
by: Oleg Ogurok | last post by:
Hi all, I have a page that's long (>400kb) and therefore takes several seconds to download. I want to put either a progress bar or a simple counter that would show how many percent of the page...
0
by: Matthew Workman | last post by:
Hello all, Does anyone know if you can force the acceptance of a save-as print dialog box programmatically? Specifically, I am opening a document locally, creating a PrintDocument, changing the...
5
by: kevin | last post by:
Hi, Any help with this would be really appreciated! I'm trying to download a file from a remote server. The access permissions is okay but the problem I'm facing is that the file is getting...
4
by: sunilj20 | last post by:
Hello, I have a requirement wherein, a user clicks on a file name in an ASP.NET web application, and the file should automatically be downloaded (Without showing the "Open", "Save As") in the...
4
by: Richard Wilde | last post by:
How do I force an XML document to be downloaded from a web browser to a client? The XML document will come ideally from a dataset but if this is not possible then I can save off the XML document...
4
by: Jofio | last post by:
I am developing a picture gallery - pictures of landscapes and various other subjects. My site has a left panel consisting of thumbnails of pictures which when clicked displays the corresponding...
5
by: Jon Paal | last post by:
how can I bypass the open/save/cancel dialog box and have the document requested open directly in the application associated with the file type ?
4
by: ATS16805 | last post by:
Hi. I wonder if it's possible to "force" a browser to "switch to SSR mode" for any given document. Specifically, I'm looking for a solution, not to a User Agent issue (i think), but a coding idea;...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.