How do I automatically delete an Excel file after creating it on a server and returning it to the us
- by David A Gibson
Hello,
I am creating an Excel file on a web server, using OleDb to connect the the physical (well as physical as it can be) file and appending records. I am then returning a FilePathResult to the user via MVC, and would like to delete the physical file afterwards due to data protection concerns over the appended records.
I have tried using a File.Delete in a Finally clause but I get a File Not Found error which must mean the file has gone when MVC is trying to send the file to the user.
I thought about creating the File as a MemoryStream but I think OleDb needs a physical file to connect to so this isn't an option.
Any suggestions on how to delete the file after returning it in one operation?
Thanks