我正在使用 Crystal Report(运行时版本 13.0.15)从 asp.net Web 应用程序生成 PDF 报告。在使用报告时,我随机收到一个 show stopper file-locked error-“System.IO.IOException-The file exists.”,之后我的报告都没有工作。但是应用程序运行良好。我进行了 IIS 重置,但问题存在。
然后我从“C:\Windows\Temp”文件夹中删除了临时文件,然后所有的报告都工作正常。
这是源代码,我用来生成报告。我没有使用 CR 查看器。所有报告都导出为 PDF。
var __reportData = GetData(filter);
ReportDocument rd = new ReportDocument();
try
{
rd.Load(rptFilePath);
rd.SetDataSource((System.Data.DataTable)__reportData);
System.IO.Stream oStream = null;
byte[] byteArray = null;
oStream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
byteArray = new byte[oStream.Length];
oStream.Read(byteArray, 0, Convert.ToInt32(oStream.Length - 1));
rd.Close();
rd.Dispose();
rd = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
catch (Exception ex)
{
if (rd != null)
{
rd.Close();
rd.Dispose();
rd = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
CrystalReportExceptionHandler.ShowError(ex, ex.Message);
}
finally
{
if (rd != null)
{
rd.Close();
rd.Dispose();
rd = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
}
最佳答案
此异常记录在 .NET 中,并在临时目录达到 65535 个文件的限制时引发。
Azure Github example/link
关于asp.net - Crystal Report - 文件存在错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50906117/