Click here to Skip to main content
12,816,406 members (30,094 online)
Rate this:
Please Sign up or sign in to vote.
Hello. I've always developed in and windows forms, but now i'm required to migrate some things to / c#. One of the problems i'm facing is Crystal Reports. In one of my projects there is a form that gets all reports in a network location and puts their names in a combo box, then the user selects one and it displays in a crystal reports viewer. Easily done... before! The problem is now in asp. I've tried several techniques and nothing works. Not even exporting.

I'm using these references in the project:
using System;
using System.IO;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Reflection;
using System.Drawing;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Net.Mail;

This is the code at page load that populates the combo box:
ReportDocument report;
Database reportDB;
Tables reportTables;
TableLogOnInfo reportLogOnInfo;
private string dirpath = @"\\NetworkLocation\";
protected void Page_Load(object sender, EventArgs e)
  DirectoryInfo dir = new DirectoryInfo(dirpath);
  foreach (FileInfo files in dir.GetFiles())
  dd_Reports.SelectedIndex = 0;

This is the code that populates the crystal report viewer:
private void ChangeRPT(string link)

CrystalReportViewer1.Visible = true;

if (IsPostBack)
CrystalReportViewer1.ReportSource = null;

ReportDocument report = new ReportDocument();


reportDB = report.Database;
reportTables = reportDB.Tables;
CrystalReportViewer1.ReportSource = report;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in reportTables)
reportLogOnInfo = table.LogOnInfo;
reportLogOnInfo.ConnectionInfo.ServerName = "server";
reportLogOnInfo.ConnectionInfo.DatabaseName = "db";
reportLogOnInfo.ConnectionInfo.UserID = "user";
reportLogOnInfo.ConnectionInfo.Password = "apass";

//report.SetDatabaseLogon("user", "pass", "server", "db");

catch (Exception)


I also have this to export to PDF:
private void ExportReport(string link)

ReportDocument report = new ReportDocument();
report.SetDatabaseLogon("user", "pass", "server", "db");

DiskFileDestinationOptions dFileDOpts = new DiskFileDestinationOptions();
ExportOptions eOpts = new ExportOptions();

dFileDOpts.DiskFileName = @"C:\rep.pdf";

eOpts = report.ExportOptions;
eOpts.DestinationOptions = dFileDOpts;
eOpts.ExportDestinationType = ExportDestinationType.DiskFile;

eOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
report.ExportToDisk(ExportFormatType.PortableDocFormat, @"C:\rep.pdf");

Response.ContentType = "application/pdf";

This is the code for the button:
protected void Button1_Click(object sender, EventArgs e)
ChangeRPT(dirpath + dd_Reports.SelectedItem.Value);
//ExportReport(dirpath + dd_Reports.SelectedItem.Value);

This is page code:
    <form id="form1" runat="server">
        <table width="100%">
                <td height="20">
                    <asp:DropDownList ID="dd_Reports" runat="server" Width = "350px">
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
                    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
                        AutoDataBind="true" />

Can anyone please just take a look at what i may be doing wrong? I'm a bit in the dark here! Any help is appreciated...

Thank you very much

[Moved from Answer - Henry]
There is no output. I found part of the problem, changed the crystal reports solution references from crystal reports 2008 to XI and it loads the reports. The problem now is with login parameters. Even though the login matches the one in the report, it still asks for credentials after the load.

I've tried both these methods but none works. It always asks for the password.
                ReportDocument cryRpt = new ReportDocument();
                TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
                TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
                ConnectionInfo crConnectionInfo = new ConnectionInfo();
                Tables CrTables;


                crConnectionInfo.ServerName = "server";
                crConnectionInfo.DatabaseName = "db";
                crConnectionInfo.UserID = "user";
                crConnectionInfo.Password = "pass";

                CrTables = cryRpt.Database.Tables;
                foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
                    crtableLogoninfo = CrTable.LogOnInfo;
                    crtableLogoninfo.ConnectionInfo = crConnectionInfo;

                CrystalReportViewer1.ReportSource = cryRpt;


                ReportDocument report = new ReportDocument();
                report.SetDatabaseLogon("user", "pass", @"server", "db");
                CrystalReportViewer1.ReportSource = report;

This is called from a button click event.
Posted 28-Jan-11 1:51am
Updated 31-Jan-11 3:50am
Henry Minute225.6K
shreekar 31-Jan-11 7:54am
What is the output?
Have you checked that the path of the reports directory is accessible from where the web page is located?
Henry Minute 31-Jan-11 8:55am
The OP has responded to your comment. I have added his response at the bottom of the original question.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 3 Dec 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100