C# Code stops after Save as dialog is closed

G

GD

Hi,
I have the following C# code in a page:

Response.ContentType = "APPLICATION/OCTET-STREAM";
Response.AppendHeader("Content-Disposition", "Attachment;
Filename=\"C:\\Download.txt\""
FileInfo fileToDownload = new FileInfo("C:\\Test.txt");
Response.Flush();
Response.WriteFile(fileToDownload.FullName);
Response.End();
string strAmIForgot = "This line doesnot get executed";

The dialog pops up and saves the file nicely. However, the code after
Response.End() doesn't get executed after the dialog is closed. Any idea or
work around?

Thanks.

GD
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

GD said:
Hi,
I have the following C# code in a page:

Response.ContentType = "APPLICATION/OCTET-STREAM";
Response.AppendHeader("Content-Disposition", "Attachment;
Filename=\"C:\\Download.txt\""
FileInfo fileToDownload = new FileInfo("C:\\Test.txt");
Response.Flush();
Response.WriteFile(fileToDownload.FullName);
Response.End();
string strAmIForgot = "This line doesnot get executed";

The dialog pops up and saves the file nicely. However, the code after
Response.End() doesn't get executed after the dialog is closed.

Of course it isn't. You end the execution with Response.End.

If you remove the Response.End, the code doesn't get executed after the
dialog is closed wither. It gets executed directly when the response is
created on the server, before the dialog pops up.
Any idea or
work around?

That depends. What is it that you are trying to do?

If you want to output anything to the browser after the download, then I
can tell you right now that you can't. The response is only the file
that gets downloaded, you can't send anything more than that.
 
G

Guest

First of all, once you make a call to Response.End() that's the END of the
Response stream. You are completely done at that point, you cannot expect to
add anything.
Secondly, you have code at the end of your sample that simply declares a
string:
string strAmIForgot = "This line doesnot get executed";
-- but your code fails to do anything with it.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
bogMetaFinder: http://www.blogmetafinder.com
 
G

GD

Thanks for reply.

What I was trying to do is to reload newly updated data to a gridview on the
page right after the dialog closes. However, it seems impossible because the
code stops right after Response.End(); and the page never gets refreshed. I
also tried to open the dialog after the the gridview is updated, which
yielded same effect probably because Response.End(); is called on server
side before page refresh is executed.

GD
 
G

GD

Peter,

The code: "string strAmIForgot = "This line doesnot get executed"; " is just
for test purpose where I can add a breakpoint to see if the compiler can
execute any code after Response.End(). Actually, what I want is to reload
newly updated data to a gridview on the same page right after the dialog
closes. It didn't work even though I call the update gridview method before
the dialog code.

Any suggestion is greatly appreciated.

GD
 

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

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top