views:

317

answers:

4

I have this lead generation form and after they give us their information, I would like the form's thank you page to popup a window where the user can save the file or open it.

This web page will be served from a Microsoft server so .net C# or javascript are options.

thx

+2  A: 

Good luck getting any browser to open an .exe file... Warning Will Robinson... Warning...

Anyways, here's a snippet....

                Response.Clear();
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + downloadName);

                while (dataToRead > 0)
                {
                    if (Response.IsClientConnected)
                    {
                        fileLength = iStream.Read(buffer, 0, buffer.Length);
                        Response.OutputStream.Write(buffer, 0, fileLength);
                        Response.Flush();
                        dataToRead = dataToRead - fileLength;
                    }
                    else
                    {
                        dataToRead = -1;//prevent infinite loop if user disconnects
                    }
                }

Edit: Ok, i suppose you could create the thank you page with a hidden button on it, inject some javascript to click that button upon load, which would then execute the code to dump the file into the response stream.

Brian Rudolph
You code, shows how to prompt save / run as dialog. But, I believe his question was about showing a thank you page and then prompt the user with this dialog.
Ramesh
+2  A: 

I Assume, your problem is to display a thank you page, and also to open a new save / run dialog.

The below js code, / HTML code in the thank you page will render the thank you page, and make the browser request for the file mentioned in the URL. If that is configured properly as mentioned by others, it will prompt the dialog

Try

Javascript

document.write("<META HTTP-EQUIV=\"refresh\" content=\".1; URL=http://domain.come/my.exe\"&gt;");

HTML

<META HTTP-EQUIV="refresh" content=".1; URL=http://domain.come/my.exe"&gt;
Ramesh
+1: I like your solution better than mine anyway.
Robert Harvey
@Robert - Thanks.
Ramesh
A: 

I would imagine your answer could be find in one of these previous questions

http://stackoverflow.com/search?q=force+download

Peter Bailey
A: 

You cannot launch a file on the users machine unless you have some ActiveX control or Java applet with permissions to do so installed.

You can create the file on your server and send it to the browser. The user will be prompted to save or open the file.

Alex
He is asking about Save / Open dialog box and is not about running the exectable.
Ramesh
I understand that. I was clarifying that this cannot be done programmatically. The user will get the prompt and they can do what they want with it.
Alex