After deploy crystal report with ASP.NET MVC 5 Error

Saeed Ahmad 20 Reputation points
2023-03-08T06:28:41.45+00:00

I am trying to deploy crystal reports project with asp.net MVC 5, using visual studio 2022. The whole website/project is running fine on localhost but when try to open crystal report page then following error show it. when i run website from visual studio 2022, crystal report load successfully. Can any one tell how to publish or deploy website with crystal report?

Server Error in '/' 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 127: public ActionResult TestReport()
Line 128: {
Line 129: ReportDocument rd = new ReportDocument();
Line 130: rd.Load(Server.MapPath("~")+ "Reports/Rolnoslips/test.rpt");
Line 131: Response.Buffer = false;| | -------- | ||

**Source File:**D:\Project\www\wifaq\wifaq\Areas\Madaris\Controllers\RollNoSlipsController.cs   **Line:**129

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) +129
CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened() +335

[CrystalReportsException: Load report failed.]
CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened() +523
CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob) +1498
CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename) +99
wifaq.Areas.Madaris.Controllers.RollNoSlipsController.TestReport() in D:\Project\www\wifaq\wifaq\Areas\Madaris\Controllers\RollNoSlipsController.cs:129
lambda_method(Closure , ControllerBase , Object[] ) +87
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +35 System.Web.Mvc.Async.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +39 System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) +77
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass11_0.<InvokeActionMethodFilterAsynchronouslyRecursive>b__0() +80
System.Web.Mvc.Async.<>c__DisplayClass11_2.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2() +396
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass3_6.<BeginInvokeAction>b__4() +50
System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__1(IAsyncResult asyncResult) +188
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +73 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +43
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +73
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +431
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +75
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +158| | -------- | ||

My controller is given here:

remember report open successfully from IIS Express visual studio, but after publish or deploy its not work


[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult TestReport()
{
            ReportDocument rd = new ReportDocument();
            rd.Load(Server.MapPath("~")+ "Reports/Rolnoslips/test.rpt");
            Response.Buffer = false;
            Response.ClearContent();
            Response.ClearHeaders();

            Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            stream.Seek(0, SeekOrigin.Begin);

            Response.AppendHeader("Content-Disposition", "inline; filename=Rolnoslips.pdf");

            return File(stream, "application/pdf");
}

Developer technologies ASP.NET Other
{count} votes

2 answers

Sort by: Most helpful
  1. EDGAR ALEJANDRO GONZALEZ TAPIA 0 Reputation points
    2023-04-05T21:52:19.6833333+00:00

    I had the same problem, Failed to open connection, but im developing in C#, the problem was when i try to export the document, did you find the solution?

    0 comments No comments

  2. Dennis Sebastian Gimenez 0 Reputation points
    2024-01-31T14:37:13.03+00:00

    I have the same problem when i call the method ExportToStream in my c# web api application throw the error ""

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.