How to Export Crystal Report in ASP.NET

Jun 1 2004 3:27 PM
Hello. I need to export a Crystal Report to PDF, I use the following code in my project: ... using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; public class WebForm1 : System.Web.UI.Page { //CR Variables ReportDocument crReportDocument; ExportOptions crExportOptions; ParameterFields crParameterFields; ParameterField crParameterField; ParameterValues crParameterValues; ParameterDiscreteValue crParameterDiscreteValue; protected IntranetV2new.ds ds1; DiskFileDestinationOptions crDiskFileDestinationOptions; protected System.Data.SqlClient.SqlConnection sqlConnection2; protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1; protected System.Web.UI.WebControls.Button Button1; private void Page_Load(object sender, System.EventArgs e) { DataSet ds = SqlHelper.ExecuteDataset(DbHelper.ConnectionString,CommandType.StoredProcedure,"spS_PruebaRas",new SqlParameter("@IdPersona",1)); ds.DataSetName="Contador"; ds.Tables[0].TableName="Contador"; DataView dv = ds.Tables["Contador"].DefaultView; dv = null; crReportDocument = new Peticion(); crReportDocument.SetDataSource(ds); report.SetDataSource(ds); //The viewer's reportsource must be set to a report before any //parameter fields can be accessed. CrystalReportViewer1.ReportSource = crReportDocument; //Get the collection of parameters from the report crParameterFields = CrystalReportViewer1.ParameterFieldInfo; //Access the specified parameter from the collection crParameterField = crParameterFields["@IdPersona"]; //Get the current values from the parameter field. At this point //there are zero values set. crParameterValues = crParameterField.CurrentValues; //Set the current values for the parameter field crParameterDiscreteValue = new ParameterDiscreteValue(); crParameterDiscreteValue.Value = 1; //Add the first current value for the parameter field crParameterValues.Add(crParameterDiscreteValue); CrystalReportViewer1.ParameterFieldInfo = crParameterFields; } //This is your sample code private void Button1_Click(object sender, System.EventArgs e) MemoryStream oStream; // using System.IO //Error in the following line: oStream = (MemoryStream)crReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); Response.Clear(); Response.Buffer= true; Response.ContentType = "application/pdf"; Response.BinaryWrite(oStream.ToArray()); Response.End(); } When I build the solution, I recieve the following message: CrystalDecisions.CrystalReports.Engine.ReportDocument' don't have a definition for 'ExportToStream' Do you know what is the problem with this code? Or you have another idea to export a report to PDF? Thanks.

Answers (7)