How to use Crystal Reports with ASP.NET?

How to use Crystal Reports with ASP.Net 2.0. Any Samples / Tutorials / Examples that show how to deploy Crystal Reports on a production server.

+6
crystal-reports
source share
3 answers

After going through pain from yourself, here are a couple of pointers that hopefully save you time ...

Crystal Reports on MSDN - there's a lot to do.

Which approach to saving should be used with Crystal Reports - gives examples of details and code on how to best manage the life cycle of a report object

This post also provides some useful tips around the life cycle of a report object.

Deployment ... Crystal Reports do not run in the 64-bit environment, so when deploying to a 64-bit server, you will either have to configure IIS to run 32-bit mode or use the previous version of the runtime. I got lucky with the runtime that comes with VS2008, this can be found in

C: \ Program Files \ Microsoft SDK \ Windows \ v6.0A \ Bootstrapper \ Packages \ CrystalReports10_5

I note that you are using ASP.NET 2.0 - I am sure there is an equivalent VS2005 runtime. Try to run the deployment environment early in the project, as this will no doubt cause more headaches than you expect.

Finally, the last moment, which cost us time, is worth mentioning - the standard parameters screen in Crystal Reports will only take you so far. If you want to get complex information about how you present your parameters to the user (for example, having parameters that depend on the choice of another parameter), you will need to minimize your own parameter screens. This is fairly easy, since the object model gives you access to all the information you need about the parameters. We took the path of creating a screen of general parameters, which is built in accordance with the parameters found in the report to which it points.

+7
source share

This is the code that I usually use:

'Generate the Report Dim oRpt As New ReportDocument Dim reportPath As String = Server.MapPath("crtTAL.rpt") oRpt.Load(reportPath) oRpt.SetDataSource(dsTAL) If Not IO.Directory.Exists(tempLocation) Then IO.Directory.CreateDirectory(tempLocation) End If If IO.File.Exists(tempLocation & filename) Then IO.File.Delete(tempLocation & filename) End If ' ******************************** ' First we must create a new instance of the diskfiledestinationoptions class and ' set variable called crExportOptions to the exportoptions class of the reportdocument. Dim crDiskFileDestinationOptions As New DiskFileDestinationOptions Dim crExportOptions As ExportOptions = oRpt.ExportOptions 'Export to Word 'append a filename to the export path and set this file as the filename property for 'the DestinationOptions class crDiskFileDestinationOptions.DiskFileName = tempLocation + filename 'set the required report ExportOptions properties With crExportOptions .DestinationOptions = crDiskFileDestinationOptions .ExportDestinationType = ExportDestinationType.DiskFile .ExportFormatType = ExportFormatType.WordForWindows End With 'Once the export options have been set for the report, the report can be exported. The Export command 'does not take any arguments Try ' Export the report oRpt.Export() oRpt.Close() oRpt.Dispose() projectCount = projectCount + 1 Catch err As Exception Response.Write("<BR>") Response.Write(err.Message.ToString) errorList = errorList & dtrProjects.Item("Title") & "; " End Try 
0
source share

What I usually use is Asp.net/C#

 public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { ///create instance of class first ReportDocument rpDoc = new ReportDocument(); ///load the report rpDoc.Load(@"TicketingBasic.rpt"); ///pass the report to method for dataInfo getDBInfo(rpDoc); /// et the source for report to be displayed CrystalReportViewer1.ReportSource = rpDoc; } protected static void getDBInfo(ReportDocument rpDoc) { ///Connection Onject ConnectionInfo cn = new ConnectionInfo(); ///DataBase,Table, and Table Logon Info Database db; Tables tbl; TableLogOnInfo tblLOI; ///Connection Declaration cn.ServerName = "??????"; cn.DatabaseName = "???????"; cn.UserID = "???????"; cn.Password = "????????"; //table info getting from report db = rpDoc.Database; tbl = db.Tables; ///for each loop for all tables to be applied the connection info to foreach (Table table in tbl) { tblLOI = table.LogOnInfo; tblLOI.ConnectionInfo = cn; table.ApplyLogOnInfo(tblLOI); table.Location = "DBO." + table.Location.Substring(table.Location.LastIndexOf(".") + 1); } db.Dispose(); tbl.Dispose(); } 

and on the Aspx side:

 <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" EnableDatabaseLogonPrompt="false" /> 
0
source share

All Articles