Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When can I delete a file after using it in Response.WriteFile()?

Tags:

asp.net

Is the WriteFile call properly synchronous, and can I delete the file written immediately after the call?

like image 297
ProfK Avatar asked Oct 14 '08 12:10

ProfK


People also ask

How to tell if a file has been deleted?

The file is actually deleted when there are no processes anymore with handles (file descriptors) to that file. You can use lsof to see if the file still has handles and when you delete such file it is often listed with the (deleted) text appended to the line.

How do I delete a file on closing an application?

If a file is open when an application terminates, the system closes it automatically. The DeleteFile function can be used to delete a file on close. A file cannot be deleted until all handles to it are closed. If a file cannot be deleted, its name cannot be reused. To reuse a file name immediately, rename the existing file.

What happens when a file is opened by a process?

When a file is opened by a process and then is deleted while the file is still open does not actually delete the file instantly. The file is actually deleted when there are no processes anymore with handles (file descriptors) to that file.

How to delete a file programmatically in Node JS?

In this Node.js Tutorial, a step by step guide is provided to delete a file with node fs and well detailed examples. Following is a step by step guide to delete a File programmatically in Node.js. Step 1: Include File System module to your Node.js program. We will use unlink () and unlinkSync () functions of this module.


2 Answers

If you're writing a file to the client with Response.WriteFile(), a call to Response.Flush() will make sure it's been fully output to the client. Once that's done you can delete it off of the webserver.

You may want to come up with a more robust system if the file is mission-critical. Say, a client-side script to validate that the file was received OK and then alerts the webserver that the file can be deleted.

like image 99
Keith Twombley Avatar answered Sep 17 '22 13:09

Keith Twombley


That is the solution, after use the syntax Response.WriteFile(fileName);, type the following code lines:

Response.Flush();
System.IO.File.Delete(fullPathFileName);
Response.End();
like image 24
ypicasso Avatar answered Sep 18 '22 13:09

ypicasso