Link to home
Start Free TrialLog in
Avatar of rborda
rbordaFlag for United States of America

asked on

CRViewer displaying The report filename was empty.

Thanks in advance for any input.
CRViewer is displaying The report filename was empty althought the report gets displayed accordingly.
I'm running a crystal report within VB.NET and using CRViewer to display the report.
Please at code and error message.


ASPX CODE:
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPagePep.master" AutoEventWireup="false"
    CodeFile="reportsCrystal.aspx.vb" Inherits="reportsCrystal" %>

<%@ Register Assembly="CrystalDecisions.Web, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
    Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div style="text-align: left; padding: 10px 0 10px 10px">
        <input id="btnBack" class="ButtonSmall" type="button" value="Back" onclick="javascript:history.back();" />
        <asp:Label ID="lblError" runat="server" Text="" ForeColor="Red"></asp:Label>
    </div>
    <div>
        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true"
            ReportSourceID="CrystalReportSource1" ToolPanelWidth="1px" />
        <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
        </CR:CrystalReportSource>
    </div>
</asp:Content>





VB CODE:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.Web
Imports CrystalDecisions.ReportSource
Imports System.Data
Imports System.Data.SqlClient
Imports CrystalDecisions.Reporting.WebControls
Imports System.IO

Partial Class reportsCrystal
    Inherits System.Web.UI.Page

    Dim _rpt As String = ""
    Dim _id As String = ""
    Protected timeout As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        getReport()

    End Sub

    Public Sub getReport()
        Try
            _rpt = Request.QueryString("rpt")
            _id = Request.QueryString("id")

            Dim objConn1 As New SqlConnection
            Dim oCom As New SqlCommand
            Dim dr As SqlDataReader

            objConn1.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnDB")
            oCom.Connection = objConn1
            objConn1.Open()
            oCom.CommandText = "sp_portal_CrystalReportUserAccessGet"
            oCom.CommandType = CommandType.StoredProcedure
            oCom.Parameters.Add(New SqlParameter("@userName", SqlDbType.NVarChar)).Value = Session("userName")
            oCom.Parameters.Add(New SqlParameter("@reportId", SqlDbType.Int)).Value = _id
            oCom.CommandTimeout = 150000
            dr = oCom.ExecuteReader

            If dr.Read Then
                If Session("userName") = dr("username") And _rpt = dr("reportName") Then
                    CrystalReportSource1.Report.FileName = "~/reportsCrystal/" & _rpt
                    lblError.Text = ""
                    CrystalReportViewer1.ViewTimeSelectionFormula = ""                  
                Else
                    lblError.Text = "Report access = 'NONE'"
                End If
            Else
                lblError.Text = "Report access = 'NONE'"
            End If
            objConn1.Close()
        Catch ex As Exception
            lblError.Text = ex.Message
        End Try
    End Sub
End Class

Open in new window

crystalerror.bmp
Avatar of Marcus Aurelius
Marcus Aurelius
Flag of United States of America image

What is the "REPORT NAME",....I don't see it in your code.....???
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rborda

ASKER

Hi CRXIuser2005:

The report name is passed thru the following field named _rpt  line 50 in the code

Avatar of rborda

ASKER

Thank you mlmcc for the link provided. I want to clarify what helped me from the link.  Using the Page_Init instead of the page_Load to declare the path as indicated on the documentation.   Thank you again!