I am trying to exporta a document to pdf and i am using crystal reports for this. everything works fine when it is not published . but when it is published it shows error :
Server Error in '/Activity' Application.
The system cannot find the path specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: The system cannot find the path specified. Source Error:
Line 28: ReportDocument rd = new ReportDocument();
Line 29: rd.Load(Path.Combine(Server.MapPath("../Reports/"), "CrystalReport1.rpt"));
Line 30: rd.SetDataSource(db.ActivityRecords.ToList());
Line 31: Response.Buffer = false;
Line 32: Response.ClearContent();
|
Source File: C:\Users\OS\source\repos\Activities\Activities\Controllers\ActivityRecordsController.cs Line: 30 Stack Trace:
[COMException (0x80004005): The system cannot find the path specified.
]
CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.Open(Object& DocumentPath, Int32 Options) +0
CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.Open(Object& DocumentPath, Int32 Options) +126
CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened() +315
|
public ActionResult exportreport()
{
ReportDocument rd = new ReportDocument();
rd.Load(Path.Combine(Server.MapPath("~/Reports"), "CrystalReport1.rpt"));
rd.SetDataSource(db.ActivityRecords.ToList());
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
try
{
Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/pdf", "Activity_List.pdf");
}
catch
{
throw;
}
//return View(db.ActivityRecords.ToList());
}