title: Crystal Reports - The process cannot access the file because it is being used by another process
body: <p>I am getting a access problem when exporting a crystal report as a pdf stream. Below is the code which runs in a background task in a ASP.net MVC web application:</p>
  
  <pre><code>using (var memoryStream = new MemoryStream())
  using (var stream = reportDoc.ExportToStream(ExportFormatType.PortableDocFormat))
  {
         stream.CopyTo(memoryStream);
         data = memoryStream.ToArray();
  }
  </code></pre>
  
  <p>Following is the stack trace of exception:</p>
  
  <pre><code>System.Runtime.InteropServices.COMException (0x80004005): The process cannot access the file because it is being used by another process.
  
     at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext)
     at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)
     at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)
     at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportOptions options)
     at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportFormatType formatType)
  </code></pre>
  
  <p>How to fix this problem?</p>