How do I automatically delete an Excel file after creating it on a server and returning it to the us

Posted by David A Gibson on Stack Overflow See other posts from Stack Overflow or by David A Gibson
Published on 2010-05-28T09:27:11Z Indexed on 2010/05/28 9:31 UTC
Read the original article Hit count: 208

Filed under:
|
|
|
|

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

© Stack Overflow or respective owner

Related posts about .NET

Related posts about excel