save as dialog

G

Guest

Hello. I am making a web application with c# and am using this code:
Response.ContentType = "application/x-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=" +
HttpUtility.UrlEncode("ã‚ã„ã†ãˆãŠ") + ".csv");
Encoding encoding = Encoding.GetEncoding("Shift-JIS");
Response.BinaryWrite(encoding.GetBytes(csvStr));
Response.End();

It works fine..the data gets saved nicely to an excel file. The user pushes
the button to download the file and then a dialog box pops up that asks if
they want to save or cancel. If the user presses the save, another dialog
box pops up where the user can change the name of the file and choose where
to save the file. The problem is that I have been told not to have two
dialog boxes pop up. When the user pushes the download button, how do I make
only the second dialog box come out? I tried

Response.Write("<script
type='text/javascript'>document.execCommand('SaveAs',null,'ã‚ã„ã†ãˆãŠ.csv');</script>");

but the webpage just gets saved to excel (not the csv file). I was told
maybe I can write some code to click the save(on the first dialog box that
pops up that asks if the want to save) so that only the second dialog comes
out(the one where the user can choose the name and location to save the file)
but I haven't figured it out. Any ideas? Please help me.
 
T

Tim Mackey

hi,
if the user clicks save, then they must also provide the location to save
it, this is a browser feature that you can't control (to my knowledge). i
personally am glad that it is not possible to manipulate the 'save' dialog
box. otherwise there would be a risk of a web site trawling your file
system without you knowing it.

i would say your best option is to open the document inline instead of
'attachment', and then if the user wants to save it they can use the
toolbars / menus etc to do that. then they will only get one dialog box.

most browsers have an option to 'always do this for this file type' in the
'open or save' dialog box. your users can tick the box if they don't want
to be asked again. it sounds like the boss has given an unreasonable
requirement based on a very shallow understanding of usability. this is the
way browsers work, it is what people are familiar with.

tim
 
T

Tim Mackey

because you have specified 'attachment' in the http header, the browser will
always prompt the user asking if they want to open or save. unless of
course they have specified a default action for the file type (browser
feature over which you have no control).

good luck
tim
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top