Delete file after downloading in c#






















How to Delete a File in C. Dinesh Beniwal Updated date Mar 07, The File class in C provides functionality to work with files. Detailed tutorials:. Next Recommended Reading. Visual Studio Vs Visual Studio Getting Started With. Collectives on Stack Overflow. Learn more. How to delete file after download with ASP. Ask Question.

Asked 11 years, 10 months ago. Active 2 months ago. Viewed 36k times. TransmitFile is called, but this hangs the application. Can I safely delete a file after user downloads it? Improve this question. George Stocker Valentin V Valentin V The solution should go in an 'answer', not in the question.

Add a comment. Active Oldest Votes. Open, FileAccess. Read, FileShare. None, , FileOptions. Octet, fileDownloadName: "File. Improve this answer. Risord Risord 1, 1 1 gold badge 14 14 silver badges 13 13 bronze badges. This worked perfectly for me. Simplest solution by far, in my opinion. I highly recommend this answer above the others. And remember to upvote Thariq Nugrohotomo's comment on this answer as well: stackoverflow. This answer worked best for me as I cannot load the file into memory due to it's size and no extra action attributes or delegates required.

Should definitely be the accepted answer. Read in the bytes of the file, delete it, call the base controller's File action. You will need to import the following namespace. Imports System. Delete File from server after download is finished. Finally, the File is deleted from the Folder Directory and the Response is terminated. MapPath string. WriteFile filePath ;. Flush ;. Delete filePath ;. End ;. MapPath String. WriteFile filePath.

Connect and share knowledge within a single location that is structured and easy to search. I'm working on a blob storage system where my files are stored. I'm trying to download a file back from my controller to browser and delete the file. So if I have a deleted file, I want to undelete it, download it then delete it again.

Soft Delete is turned on Is there a way to do this so deletion executes after return statement. Are you facing the error "the blob is not found" in your current code?

If yes, you can use MemoryStream and blob. DownloadToStream memoryStream , then you can just delete the blob after download completes, no need to call delete after return statement.

I installed this nuget package of blob storage: Microsoft. Blob, Version You can use this package or change your current code to async as per the comment. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?



0コメント

  • 1000 / 1000