crystal report exception the file exists System.IO.Path.InternalGetTempFileName Edit

Murugan Andezuthu Dharmaratnam | 15 October 2020 | 128

In my asp .net MVC application, I am using crystal reports to generate PDF reports. The application was working fine and was able to generate the reports. But suddently the crystal reports stopped working and started throwing the exception below.

{"Message":"An error has occurred.","ExceptionMessage":"The file exists.\r\n","ExceptionType":"System.IO.IOException","StackTrace":" at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)\r\n at System.IO.Path.InternalGetTempFileName(Boolean checkHost)\r\n at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)\r\n at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)\r\n at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)\r\n at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToDisk(ExportFormatType formatType, String fileName)


The solution was to remove the temp files from the "C:\Windows\Temp" folder. Once the files were removed from the temp folder the reports started working fine. This exception is documented in .NET and is raised when the temp directory reaches the limit of 65535 files.