DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Wed, 8 Aug 2007 17:24:49 -0500,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    GD
          2    Göran Andersson
          3    Peter Bromberg [C# MVP]
          4    GD
          5    GD


C# Code stops after Save as dialog is closed   
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
Date:Wed, 8 Aug 2007 17:24:49 -0500   Author:  

Re: C# Code stops after Save as dialog is closed   
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.

-- 
Gran Andersson
_____
http://www.guffa.com
Date:Thu, 09 Aug 2007 01:03:47 +0200   Author:  

RE: C# Code stops after Save as dialog is closed   
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
> 
> 
> 
> 
> 
Date:Wed, 8 Aug 2007 17:10:00 -0700   Author:  

Re: C# Code stops after Save as dialog is closed   
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

"Gran Andersson"  wrote in message 
news:OppEpBh2HHA.5740@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.
>
> -- 
> Gran Andersson
> _____
> http://www.guffa.com 
Date:Wed, 8 Aug 2007 23:18:55 -0500   Author:  

Re: C# Code stops after Save as dialog is closed   
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]"  wrote 
in message news:D35D46C2-ECBA-401C-A5B9-23B50B5E5E1D@microsoft.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
>>
>>
>>
>>
>> 
Date:Wed, 8 Aug 2007 23:28:05 -0500   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us