473,413 Members | 1,778 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,413 software developers and data experts.

C# Code stops after Save as dialog is closed

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


Aug 8 '07 #1
4 7648
GD wrote:
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öran Andersson
_____
http://www.guffa.com
Aug 8 '07 #2
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

"GD" wrote:
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


Aug 9 '07 #3
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öran Andersson" <gu***@guffa.comwrote in message
news:Op**************@TK2MSFTNGP04.phx.gbl...
GD wrote:
>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öran Andersson
_____
http://www.guffa.com

Aug 9 '07 #4
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

"Peter Bromberg [C# MVP]" <pb*******@yahoo.yohohhoandabottleofrum.comwrote
in message news:D3**********************************@microsof t.com...
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

"GD" wrote:
>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



Aug 9 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: TM360 | last post by:
I realize this may not be the right group to post this, but I'm not having much success elsewhere so I thought I'd give it a try... In our application we have a link that opens a new window...
3
by: Jay | last post by:
Hey there, Is there a way to have php automatically save a file that is being downloaded without having the annoying "Save As.." dialog box that appears? I would like to be able to create a txt...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
5
by: MLH | last post by:
Having identified a A97 bug in which acDialog causes undesirable side effects processing the opened form, I would like to replace the following code running in MyForm ... DoCmd.OpenForm...
4
by: Adam | last post by:
I have a form that has a timer running on it (System.Timers.Timer). On this form, I have a button that opens a Common Dialog box. As soon as this button is pressed, the timer stops running. When I...
2
by: reshm | last post by:
In my application i have file save & file open button i use common dialog box to save the file but simultaneously i want to show progrss bar to show the progess. how can i do?
1
by: dan.c.roth | last post by:
oForm.Close() vs this.Close() in a modal dialog. oFrom.Close() calls Form.Dispose() but this.Close() ,say in the click event of the Form, does not. I can think of the reason for this but is...
11
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok /...
6
by: thesinnerishere | last post by:
hello! how can the save task be completed when the popup is closed in javascript. for eg i have this save function. so when i click on the OK of confirmation dialog box , the popup should also...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.