Question

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
Was it helpful?

Solution

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.

OTHER TIPS

If you browse to the wwwroot folder, and drag the aspnet_client folder to your project, then it will add all the files.

C:\inetpub\wwwroot

I'm still working on getting this one working, as just doing this hasn't yet been sufficient.

The seemingly best article on the topic I've found so far is: http://scn.sap.com/community/crystal-reports-for-visual-studio/blog/2011/01/12/how-do-i-resolve-bobj-is-undefined-issue

However, I've now tried steps 1 & 4, but so far have had no success...

Following are the solutions to the above scenarios:

1.Copy the folder "crystalreportviewers12" from “C:\Inetpub\wwwroot\system_web\2_0_50727" under “Default Website” to the “Custom Website” directory in IIS. Or, create a virtual directory pointing ‘aspnet_client’ folder in the custom web site directory.

2.In the IIS Manger, select the Application Pool and Basic Settings. Under Managed Pipeline Mode, change Integrated Mode to Classic Mode.

3.The value of resoureURI should be "~/crystalreportviewers12" not "/crystalreportviewers12".

4.Copy the CrystalReportViewers12 folder from "C:Program Files\Business Objects\Common\4.0" and paste it to "C:\Windows\Microsoft.NET\Framework\v3.5\ASP.NETClientFiles".

Note: Framework may vary as per the Visual Studio version used.

My Error:

0x800a1391 - JavaScript runtime error: 'bobj' is undefined

bobj.crv.stateManager.setComponentState('CrystalReportViewer1__UI',eval('('+document.getElementById('__CRYSTALSTATECrystalReportViewer1').value+')'));

Somehow I seem to have a conflict with different versions. VS wants to use 4_6_30, but I seem to have elsewhere the folders for 4_0_30319...

So playing around I can get it to drop the bobj error, but it still does not display the report viewer. If specifying a report, now I just get that loading the report failed... and yet I let it create a new report via VS...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top