SaveAs excel Dialog and IIS ConnectionTimeOut


N. Shehzad

I have a following code that allows a user to download excel file. However
if the download dialog has been sitting there for more than two minutes which
is connectiontimeout setting on IIS, user cannot download the file, and it
results in error. How can I keep the connection open, so that if users goes
for restroom break, and meanwhile the popup saveAs dialog has shown up
without changing the connectionTimeOut property on the IIS server?

//request was not aborted
Response.ContentType = "application/";
Response.AddHeader("Content-Disposition", "attachment;
filename=" + _fileDisplayName);
Response.Charset = "";
if (System.IO.File.Exists(Server.MapPath(".") + "\\" +
Response.TransmitFile(Server.MapPath(".") + "\\" +

Gregory A. Beamer

How can I keep the connection open, so that if users goes
for restroom break, and meanwhile the popup saveAs dialog has shown up
without changing the connectionTimeOut property on the IIS server?

In your post, you are asking "solve my problem the way I want to solve it"
rather than focusing on the problem. I see two potential problems:

1. User clicks button and then ignorantly walks away in the few seconds it
takes to produce the file (ie, does not understand how web apps work)
2. User clicks button and the creation process takes so damned long he has
to pee.

In other words, which of these are we actually solving:

"How can I use technology to protect users who don't understand how the web
"The time to create the Excel file is so long, the person's bladder gets
full before it is finished".

NOTE: Without focusing on the true problem (disease?), you are only abating
symptoms. If a doctor prescribed pain pills for cancer, you would fire him,
as he is not fighting the disease. So, be a good doctor and fight the
disease, not the symptoms. I have two paths you can go down, depending on
what the disease, not the symptom, is.

Assuming the technology needs to protect ignorant users
Unfortunately, anything you do will only prolong the agony, but here are
some things you can try if you truly want to protect users from clicking "I
want this file" and then immediately saying "I need to pee".

1. Increase timeout in IIS - has ramifications on scale and performance, but
it is an option
2. Create a download manager and queue up downloads so the download does not
start any part of the process until the guy figures he is done urinating
3. Use a technology that allows more time, as you can control the process
better than HTML/HTTP - Silverlight comes to mind

If you coded a modal dialog, you could time it out. With IE, the popup is on
the user side. But you might find a clever way to shut the dialog down and
redirect the user to a "don't walk away from the machine when you request a

Assuming the process takes too long:
The other implication here is the save dialog is taking too long to display,
which is a completely different issue. If it takes too long to create the
Excel file, I would consider doing this asynch and alerting the user when he
can download. Then there is no time to go and pee after he clicks the link.

Important takeaway:
You have to figure out which is the real problem (time to create file or
user is not getting it) and aim at that problem. If the file is taking too
long, then trying to protect the user is a foolish direction to head in, as
it DOES NOT solve the real problem. It only masks the symptoms.

Peace and Grace,

Twitter: @gbworld

| Think outside the box! |

Andrew Morton

N. Shehzad said:
if (System.IO.File.Exists(Server.MapPath(".") + "\\" +

Just incidentally, you may find it a bit neater to use Server.MapPath("~/" +
_xlFileName) to get the file.

Regarding the timeout issue, does it take a long time for the "Save As..."
dialog to appear, or do the users get the dialog up and then walk off?

If the former, you could try a Response.Flush() after setting the headers so
that /something/ is sent to the browser to give it a chance to show the
dialog quickly. Also, using an HttpHandler (in an .ashx file) could improve
the response time as it involves less overhead.

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

No members online now.

Forum statistics

Latest member

Latest Threads