Solved

how do you execute code after the user downloads a file?

Posted on 2006-07-12
6
846 Views
Last Modified: 2008-02-01
Hello,

I have code that prompts the user to download a file (a word document).  I am using asp.net 1.1 C#

My problem is, that after the user downloads the file, the request ends.  Nothing else will execute on the page.  For example:

 Response.Clear();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + strOriginalFileName + "." + strFileToUploadExtension);
                Response.AddHeader("Content-Length", file.Length.ToString());
                Response.ContentType = "application/octet-stream";
                Response.WriteFile(file.FullName);
                Response.End();

                string newString;
                System.IO.File.Delete(strFilePath);

the File.Delete()...

will not execute after the user downloads teh file.


Does anyone know how to fix this?

Thanks
0
Comment
Question by:alexthecodepoet
  • 3
  • 2
6 Comments
 
LVL 35

Expert Comment

by:mrichmon
ID: 17095824
As soon as you issue the Response.End command you cannot send back anything else ass you have told the browser the response is complete.

I think you are going to be stuck doing that if you are streaming content.

You could try issuing the command right before the Response.End, but I don't knwo what it will do to delete the file before the response has ended.
0
 

Author Comment

by:alexthecodepoet
ID: 17095898
i see,

so then, is it possible to keep running code?  or can you think of any alternatives?

Thanks,

0
 
LVL 35

Expert Comment

by:mrichmon
ID: 17095922
I don't understand what you mean by "keep code running"
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:alexthecodepoet
ID: 17095983
once i call the code that lets the user download the file, i need to keep running code..
that is, when i do this:

Response.WriteFile(file.FullName);
Response.End();

I then need to delete the file.

But the page stops running or something after i do Response.End();  so how do i go about executing code after i do Response.End();

?

Thanks
0
 
LVL 5

Accepted Solution

by:
Jojo1771 earned 500 total points
ID: 17095987
Simply move your   Response.End(); to the end of the page event prerender.  I'm guessing

If I follow you. You want the user to dl a file then run some other code. By moving the   Response.End(); to the  end of prerender you should be able to 1 write it out to the buffer. Then delete the file as its byte array is now in the buffer then in prerender send the   Response.End(); So the page never accatully renders. The user won't see anything until you issure the   Response.End(); But lets face it, I think we are talking nano seconds.

Thanks,
Jojo1771
0
 

Author Comment

by:alexthecodepoet
ID: 17096177
It turns out that you can just remove the Response.End alltogether and everythign works out dandy :)

Thanks!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now