Set Crystal Report path which is in other Folder (Directory) using C# and VB.Net in Windows Application

Last Reply 5 months ago By dharmendr

Posted 5 months ago

I created separate folder for crystal report in windows form and structure looks like this 

myProject -> AB -> Crystal Report -> rptStuData

rptStuData is crystal report which is created by using wizard

Now I want to display the data in the rptStuData.

guide me how i can do that?

You are viewing reply posted by: dharmendr 5 months ago.
Posted 5 months ago

Hi smile,

You have to manually load the report in ReportDocument using the path.

For crystal report refer below article.

Basic Crystal Report Tutorial with example in Windows Forms (WinForms) Application using C# and VB.Net

Change the Form1_Load event code with below.

C#

private void Form1_Load(object sender, EventArgs e)
{
    Customers dsCustomers = GetData();
    ReportDocument crystalReport = new ReportDocument();
    crystalReport.Load(Application.StartupPath.Replace("bin\Debug","") + "AB\\CrystalReport\\rptStuData.rpt");
    crystalReport.SetDataSource(dsCustomers);
    this.crystalReportViewer1.DisplayGroupTree = false;
    this.crystalReportViewer1.ReportSource = crystalReport;
    this.crystalReportViewer1.RefreshReport();
}

VB.Net

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
    Dim dsCustomers As Customers = GetData()
    Dim crystalReport As ReportDocument = New ReportDocument()
    crystalReport.Load(Application.StartupPath.Replace("bin\Debug","") & "AB\CrystalReport\rptStuData.rpt")
    crystalReport.SetDataSource(dsCustomers)
    Me.crystalReportViewer1.DisplayGroupTree = False
    Me.crystalReportViewer1.ReportSource = crystalReport
    Me.crystalReportViewer1.RefreshReport()
End Sub