Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-07-12
6
Medium Priority
?
852 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

885 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