Solved

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

Posted on 2006-07-12
6
844 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 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

15 Experts available now in Live!

Get 1:1 Help Now