I found a post about using disposable object with the download action. However I found the file I created was disposed before the download action therefore it returned "Could not find file..." error. Any idea? Thanks you.
below is my code
public FileResult DownloadPDF(int id)
{
var downloadFileName = id.ToString() + "_" + DateTime.Now.ToString("yyyyMMddHHmmss")+".pdf";
// TemporaryFileHelper implements the Idisposable
using(TemporaryFileHelper tempDownloadFile = new TemporaryFileHelper())
{
//obtain temp file name and path
var tempFileNameAndPath = tempDownloadFile.GetTempFileNameWithPath();
//generate temp file with above file name and path
_pdfReportServices.GenerateTempPdfForDownload(id, tempFileNameAndPath);
//return file result
return File(tempFileNameAndPath, "application/pdf", Server.UrlEncode(downloadFileName));
}
}