473,385 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to open a CrystalReport in ASP.Net C#?

Hi,

Would someone tell me how to open a CrystalReport in my ASP.Net C#?
We can use the Show method to open a windows form,
but what method should we use for opening a CrystalReport?
Thanks for help.
Jason
Nov 17 '05 #1
1 3009

"Jason Huang" <Ja************@hotmail.com> wrote in message
news:u9**************@TK2MSFTNGP15.phx.gbl...
Hi,

Would someone tell me how to open a CrystalReport in my ASP.Net C#?
We can use the Show method to open a windows form,
but what method should we use for opening a CrystalReport?


Here's some "quick & dirty" code. There are a LOT of things wrong with this
code, so please use it as an example only!!

There's a "selection page" that retrieves the data and loads the report (if
you use the "pull" method of Crystal Reports you wouldn't need to retrieve
the data). The selection page then redirects to a generic "viewer page" that
sends appropriate output back to the client browser.

Selection page:

private void btnSummaryReport_Command(object sender,
System.Web.UI.WebControls.CommandEventArgs e)
{
// Retrieve the report data.
string tSQL = "select PaymentMethod, sum(TotalPriceAdult) as
TotalPriceAdult "
+ " from TicketMaster"
+ " where MasterNumber > '0'";

if ( BeginningDate.Text.Trim() != string.Empty )
tSQL += " and TransactionDate >= '"+BeginningDate.Text+"' ";
if ( EndingDate.Text.Trim() != string.Empty )
tSQL += " and TransactionDate <= '"+EndingDate.Text+"' ";
if ( Location.SelectedValue.Trim() != "A" )
tSQL += " and Location = '"+Location.SelectedValue+"' ";
if ( UserCode.SelectedValue.Trim() != "A" )
tSQL += " and UserId = '"+UserCode.SelectedValue+"' ";

tSQL += " group by PaymentMethod order by PaymentMethod ";

SqlConnection conn = new
SqlConnection(ConfigurationSettings.AppSettings["SqlConnectionString"]);
SqlDataAdapter data = new SqlDataAdapter(tSQL,conn);
DataSet ds = new DataSet();
data.Fill(ds);

// Set up the Crystal Report objects.
CrystalDecisions.CrystalReports.Engine.ReportDocum ent rpt = new
CrystalDecisions.CrystalReports.Engine.ReportDocum ent();
rpt.Load(System.Configuration.ConfigurationSetting s.AppSettings["ReportDirectory"]+"RevenueSummary.rpt");
rpt.SetDataSource(ds.Tables[0]);

// Session variables required for the report viewer page.
Session["ReportSource"] = rpt;
Session["ReportDataSet"] = ds;
Response.Redirect("ReportViewer.aspx?ReportType="+ ReportType.SelectedValue,true);
}

In the "Report Viewer" page, there's this:

private void Page_Load(object sender, System.EventArgs e)
{
CrystalDecisions.CrystalReports.Engine.ReportDocum ent tDoc =
(CrystalDecisions.CrystalReports.Engine.ReportDocu ment)Session["ReportSource"];
_reportType = Request.Params["ReportType"];
if ( tDoc != null )
{
CrystalReportViewer1.ReportSource = tDoc;
if ( _reportType == "XLS" )
ExportToExcel();
else if ( _reportType == "XLSRAW" )
ExportRawToXLS();
else if ( _reportType == "XML" )
ExportToXML();
else if ( _reportType == "CSV" )
ExportToCSV();
else
ExportToPDF();
}
}

I've never found the Crystal web report viewer (that outputs HTML) very
useful. We default everything to PDF. I guess if you wanted to use the
"drill down" functionality the built in HTML viewer might be nice.

private void ExportToPDF()
{
string _filename =
System.Configuration.ConfigurationSettings.AppSett ings["TempDirectory"] +
Session.SessionID.ToString() + ".pdf";
DiskFileDestinationOptions crDiskFileDestinationOptions = new
DiskFileDestinationOptions();
crDiskFileDestinationOptions.DiskFileName = _filename;
CrystalDecisions.CrystalReports.Engine.ReportDocum ent tDoc =
(CrystalDecisions.CrystalReports.Engine.ReportDocu ment)Session["ReportSource"];
CrystalDecisions.Shared.ExportOptions crExportOptions =
tDoc.ExportOptions;
crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
tDoc.Export();

// The following code writes the pdf file
// to the Client's browser.
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.WriteFile(_filename);
Response.Flush();
Response.Close();

// delete the exported file from disk
System.IO.File.Delete(_filename);
}
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: s-galit | last post by:
i read on the msdn site that the crystalReport is dynamic does someone know if its possible to hide a column on the crystalReport dynamicly?? how? where i can get examples? thanks
0
by: s-galit | last post by:
hi, i have a formula parameter in my crystalReport how can i initalize the parameter so that in every line in the crystalReport the parameter will have a different string? how to get to line in...
0
by: s-galit | last post by:
hi, is it possible to give a different value to a formula field in the crystalReport (i mean a different value in every row in the crystalReport) ? if yes then how can i get to a row? thanks in...
2
by: Vlatko | last post by:
I have made a simple application in C# that prints a txt file using CrystalReport. On my PC everything works fine but when I run my app on another PC it collapses. I get message: "Cannot find...
2
by: Don Wash | last post by:
Hi All! I've been searching everywhere for a simple sample of producing a bar graph using CrystalReport by specifying SQL Query, and I've found none of it! I find so many complex samples with so...
0
by: agcabutotan | last post by:
Hi to everyone. I am new in this thread, please help me. I'm having difficulty with CrystalReport.Net. I have a completed project written and compiled in VB.Net (and I used CrystalReport.Net in...
1
by: mhsasono | last post by:
Hi all, Has anybody experienced with CrystalReport? My question is: Does CrystalReport have capability to print the Microsoft Word document? Reason: I want to know CrystalReport capability...
0
by: amri | last post by:
How to define CrystalReport object in ASP.NET ? I take a CrystalReportViewer & CrystalReportSource........& their name is in CrystalReport is respectively CrystalReportViewer1 & ...
0
by: amri | last post by:
How to define CrystalReport object in ASP.NET ? I take a CrystalReportViewer & CrystalReportSource........& their name is in CrystalReport is respectively CrystalReportViewer1 & ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.