Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my Crystal Report and Viewer invisible on a Web Form in an MVC application?

I'm copying code from an example MVC 3 application into my new MVC 4 application. The code sets report parameters into Session, i.e. the report name and the report data, and then calls an .aspx page with only a CrystalReportViewer on it to show the report:

public class ReportController : Controller
{
    public ActionResult Terminal()
    {
        Session["ReportName"] = "Terminal.rpt";
        using (var sqn = new SqlConnection("Data Source=(Local);Initial Catalog=ParkPay;Integrated Security=SSPI;MultipleActiveResultSets=True;"))
        {
            var adap = new SqlDataAdapter("select * from parkpay.Terminal", sqn);
            var dt = new DataTable();
            adap.Fill(dt);
            Session["ReportData"] = dt;
        }
        return RedirectToAction("ShowReport", "AspxReportViewer");
    }
}

public class AspxReportViewerController : Controller
{
    public void ShowReport()
    {
        Response.Redirect("~/AspxForms/ReportViewer.aspx");
    }
}

The web form:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportViewer.aspx.cs" Inherits="ParkPay.Reports.Crystal.AspxForms.ReportViewer" %>

<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form" runat="server">        
        <CR:CrystalReportViewer ID="CrystalReportViewer" runat="server" AutoDataBind="true" />
    </form>
</body>
</html>

The two projects - mine and the example - are nearly identical, yet when I call a report action such as Terminal on my project, all I get is a blank page. It has a Crystal viewer on it, which is a div full of JavaScript way beyond my level.

The main work is done in the code behind for ReportViewer.aspx:

protected void Page_Load(object sender, EventArgs e)
{
    var reportDoc = new ReportDocument();
    var reportName = Session["ReportName"].ToString();
    var dataSource = Session["ReportData"] as DataTable;
    var reportPath = Path.Combine(Server.MapPath("~/Reports"), reportName);
    reportDoc.Load(reportPath);
    reportDoc.SetDataSource(dataSource);
    CrystalReportViewer.ReportSource = reportDoc;
}

This is identical in both the example and my project. If I copy one of my reports to the example project, it works perfectly. Both web.config files look identical. There are no 'special' files in the example report not in mine. The only obvious difference is my project is the startup project in a small solution, where the example project is standalone. In a solution, but alone there.

What could either be wrong with mine, or what could be the difference? I'm thinking of simply moving all my reports to the example and calling out to it from my project.

NOTE: The JavaScript console shows these errors:

Failed to load resource: the server responded with a status of 404 (Not Found):  http://localhost:17441/aspnet_client/system_web/4_0_30319/crystalreportviewers13/js/crviewer/crv.js

and

Failed to load resource: the server responded with a status of 404 (Not Found):  http://localhost:17441/aspnet_client/system_web/4_0_30319/crystalreportviewers13/js/crviewer/images/style.css

and the two

Uncaught ReferenceError: bobj is not defined:   ReportViewer.aspx:56 ReportViewer.aspx:64
like image 619
ProfK Avatar asked Aug 03 '13 22:08

ProfK


People also ask

Why is my crystal report blank?

A report might be blank or missing data if the wrong fields are being used, the wrong criteria is in the Select Expert, or the table joins are not set to Left Outer Join.

How do I show Crystal Reports?

Open Visual Studio and click New Project -> Window Form Application. Give the name of the project and click OK. Subsequently, choose the project, go to the Solution Explorer -> Right click on project name -> Add -> New Item. Click Reporting-> Crystal Reports and click 'Add' button.

What is the use of Crystal Report Viewer?

Use SAP Crystal Reports Viewer to create and save customized views of your data without the need for a report engine, a designer or help from IT. View report files (. RPT) on both PC and Mac computers.


1 Answers

Aha the old bobj is not defined!

This means you're running the ASP in a different site from the Default Site in IIS. When you install Crystal Reports it puts a bunch of files in C:\Inetpub\wwwroot\aspnet_client that are necessary for report viewer to work.

Solution: Copy the crystal files beneath C:\Inetpub\wwwroot\aspnet_client to your website root folder.

To get the right path, go to IIS Manager > Sites > [your website] > right-click > Manage Web Site > Advanced Settings... > Physical Path. The actual files you need are beneath wwwroot\aspnet_client\system_web\[framework version]\crystalreportviewers13 but it's usually simplest to just copy the entire aspnet_client folder from the default webroot to your site's webroot.

like image 54
Rory Avatar answered Oct 13 '22 19:10

Rory