Response.WriteFile

C

christof

I have situation like this, a file is made on server, then the clinet is
downloading it to his machine and afterwards i wish to delete file on
the server, unfortunately if i'm doing it like that, it doesn't work:



Response.AppendHeader("content-disposition","attachment;
filename="+txtFileName.Text);
Response.ContentType = "application/x-msdownload";
Response.WriteFile((string)ViewState["backupFile"]);

File.Delete((string)ViewState["backupFile"]);

- the file is deleted before this dialog launches, if i ommit the last
line dialog is shown, client saves the file, and it's fine.

How to force my app to wait before user saves the file and right then
when it's done - delete the file on server?

Thx
 
E

Erik Funkenbusch

How to force my app to wait before user saves the file and right then
when it's done - delete the file on server?

You can't.

Your best bet is create the file in some temporary directory, then every so
often delete all the files in that directory that are older than a certain
amount of time (this prevents you from possibly deleting files that have
sent requests but have not actually started downloading yet).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top