Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-07-12
6
Medium Priority
?
850 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

721 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