I'm trying to use Controller.File
to return a FilePathResult
from a view in my ASP.NET MVC 2 project. I use it like this:
return File(pdfFilePath, "application/pdf", "foo.pdf");
However I keep getting this error in the yellow screen of death:
The process cannot access the file [the file path] because it is being used by another process.
This error usually comes up when you forget to close a file stream, but I figured that this should be taken care of by the ASP.NET MVC framework. This doesn't happen every time, but rather periodically. Sometimes I get the file just fine but then it just stops working. I am using the development server when testing this.
Any ideas?