| Wolfgang Baeck |
Hi,
I implemented the export sample from CR and my report never exports to my server. I don't get an error, there is just nothing there in the directory or any other directory for that matter. Any Idea? Attached is my source.
Wolfgang
using System; using System.IO; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using CrystalDecisions.Shared; using CrystalDecisions.CrystalReports.Engine;
namespace HopeAndHome.Admin { public class AccForPeriod : System.Web.UI.Page { protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1; // CR variables ReportDocument crReportDocument; ExportOptions crExportOptions; DiskFileDestinationOptions crDiskFileDestinationOptions; Database crDatabase; Tables crTables; TableLogOnInfo crTableLogOnInfo; ParameterFields crParameterFields; ParameterField crParameterField; ParameterValues crParameterValues; ParameterDiscreteValue crParameterDiscreteValue; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.DropDownList DropDownList1; protected System.Web.UI.WebControls.Button Button1; ConnectionInfo crConnectionInfo;
private void Page_Load(object sender, System.EventArgs e) { try { this.setExportOptions(); this.prepareReport(); } catch (Exception ex) { Label1.Text = ex.ToString(); Label1.Visible = true; } }
#region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load);
} #endregion private void setExportOptions() { // ******************************************* // Initialize Dropdownlist for Format types // ******************************************* DropDownList1.Items.Add(""); DropDownList1.Items.Add("Rich Text (RTF)"); DropDownList1.Items.Add("Portable Document (PDF)"); DropDownList1.Items.Add("MS Word (DOC)"); DropDownList1.Items.Add("MS Excel (XLS)"); DropDownList1.Items.Add("Crystal Report (RPT)"); DropDownList1.Items.Add("HTML 3.2 (HTML)"); DropDownList1.Items.Add("HTML 4.0 (HTML)"); } private void prepareReport() { crReportDocument = new ReportDocument();
crReportDocument.Load("c:\\inetpub\\wwwroot\\hopeandhome\\reports\\MonthlyAc counting.rpt",CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempCopy) ; crDatabase = crReportDocument.Database; crTables = crDatabase.Tables;
crConnectionInfo = new ConnectionInfo(); crConnectionInfo.ServerName = "HopeAndHome"; crConnectionInfo.DatabaseName = "HopeAndHome"; crConnectionInfo.UserID = "user"; crConnectionInfo.Password = "password";
foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in crTables) { crTableLogOnInfo = aTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectionInfo; aTable.ApplyLogOnInfo(crTableLogOnInfo); }
CrystalReportViewer1.ReportSource = crReportDocument;
crParameterFields = CrystalReportViewer1.ParameterFieldInfo; crParameterField = crParameterFields["@AccStartDate"]; crParameterValues = crParameterField.CurrentValues; crParameterDiscreteValue = new ParameterDiscreteValue(); crParameterDiscreteValue.Value = "6/30/2002"; crParameterValues.Add(crParameterDiscreteValue);
crParameterField = crParameterFields["@AccEndDate"]; crParameterValues = crParameterField.CurrentValues; crParameterDiscreteValue = new ParameterDiscreteValue(); crParameterDiscreteValue.Value = "7/31/2002"; crParameterValues.Add(crParameterDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo = crParameterFields; } private void ExportReport() { // This subroutine uses a case statement to determine the selected export format from the dropdownlist // menu and then sets the appropriate export options for the selected export format. The report is // exported to a subdirectory called "Exported".
// ******************************** //Check to see if the application directory has a subdirectory called "Exported". //If not, create the directory since exported files will be placed here. //This uses the Directory class of the System.IO namespace. string ExportPath; //ExportPath = Request.PhysicalApplicationPath + "Exported\\"; //if (Directory.Exists(ExportPath) == false) Directory.CreateDirectory(Request.PhysicalApplicationPath + "Exported\\"); ExportPath = @"\HopeAndHome\Upload\"; // ********************************
// First we must create a new instance of the diskfiledestinationoptions class and // set variable called crExportOptions to the exportoptions class of the reportdocument. crDiskFileDestinationOptions = new DiskFileDestinationOptions(); crExportOptions = crReportDocument.ExportOptions;
//Find the export type specified in the dropdownlist and export the report. The possible export format //types are Rich Text(RTF), Portable Document (PDF), MS Word (DOC), MS Excel (XLS), Crystal Report (RPT), //HTML 3.2 (HTML) and HTML 4.0 (HTML) // //Though not used in this sample application, there are options that can be specified for various format types. //When exporting to Rich Text, Word, or PDF, you can use the PdfRtfWordFormatOptions class to specify the //first page, last page or page range to be exported. //When exporting to Excel, you can use the ExcelFormatOptions class to specify export properties such as //the column width etc.
if (DropDownList1.SelectedItem.Text == "Rich Text (RTF)") { //-------------------------------------------------------------------- //Export to RTF.
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class crDiskFileDestinationOptions.DiskFileName = ExportPath + "RichTextFormat.rtf";
//set the required report ExportOptions properties crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.RichText; crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "Portable Document (PDF)") { //-------------------------------------------------------------------- //Export to PDF
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class crDiskFileDestinationOptions.DiskFileName = ExportPath + "PortableDoc.pdf";
//set the required report ExportOptions properties crExportOptions.DestinationOptions = crDiskFileDestinationOptions; crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "MS Word (DOC)") { //-------------------------------------------------------------------- //Export to Word
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class crDiskFileDestinationOptions.DiskFileName = ExportPath + "Word.doc";
//set the required report ExportOptions properties crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.WordForWindows; crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "MS Excel (XLS)") { //-------------------------------------------------------------------- //Export to Excel
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class crDiskFileDestinationOptions.DiskFileName = ExportPath + "Excel.xls";
//set the required report ExportOptions properties crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.Excel; crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "Crystal Report (RPT)") { //-------------------------------------------------------------------- //Export to Crystal reports:
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class crDiskFileDestinationOptions.DiskFileName = ExportPath + "Report.rpt";
//set the required report ExportOptions properties crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.CrystalReport; crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "HTML 3.2 (HTML)") { //-------------------------------------------------------------------- //Export to HTML32:
HTMLFormatOptions HTML32Formatopts = new HTMLFormatOptions();
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.HTML32;
HTML32Formatopts.HTMLBaseFolderName = ExportPath + "Html32Folder"; //Foldername to place HTML files HTML32Formatopts.HTMLFileName = "HTML32.html"; HTML32Formatopts.HTMLEnableSeparatedPages = false; HTML32Formatopts.HTMLHasPageNavigator = false;
crExportOptions.FormatOptions = HTML32Formatopts; //-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "HTML 4.0 (HTML)") { //-------------------------------------------------------------------- //Export to Html 4.0:
HTMLFormatOptions HTML40Formatopts = new HTMLFormatOptions();
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.HTML40;
HTML40Formatopts.HTMLBaseFolderName = ExportPath + "Html40Folder"; // Foldername to place HTML files HTML40Formatopts.HTMLFileName = "HTML40.html"; HTML40Formatopts.HTMLEnableSeparatedPages = true; HTML40Formatopts.HTMLHasPageNavigator = true; HTML40Formatopts.FirstPageNumber = 1; HTML40Formatopts.LastPageNumber = 3;
crExportOptions.FormatOptions = HTML40Formatopts; } //export format
//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 crReportDocument.Export(); } catch (Exception err) { Response.Write("<BR>"); Response.Write(err.Message.ToString()); } }
private void Button1_Click(object sender, System.EventArgs e) { this.prepareReport(); this.ExportReport(); } } }
|
|
| |
| |
| Tim Musschoot |
What kind of error ?
You forgot to call
crReportDocument.Close(); crReportDoucment = null; // not really necessairy !
Tim Musschoot Software Engineer AspFriends Moderation Team Click here to reveal e-mail address http://www.aspalliance.com/timmusschoot
-----Oorspronkelijk bericht----- Van: Wolfgang Baeck [mailto:Click here to reveal e-mail address] Verzonden: woensdag 14 augustus 2002 18:33 Aan: ngfx-crystal Onderwerp: [ngfx-crystal] Unable to export a report
Hi,
I implemented the export sample from CR and my report never exports to my server. I don't get an error, there is just nothing there in the directory or any other directory for that matter. Any Idea? Attached is my source.
Wolfgang
using System; using System.IO; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using CrystalDecisions.Shared; using CrystalDecisions.CrystalReports.Engine;
namespace HopeAndHome.Admin { public class AccForPeriod : System.Web.UI.Page { protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1; // CR variables ReportDocument crReportDocument; ExportOptions crExportOptions; DiskFileDestinationOptions crDiskFileDestinationOptions; Database crDatabase; Tables crTables; TableLogOnInfo crTableLogOnInfo; ParameterFields crParameterFields; ParameterField crParameterField; ParameterValues crParameterValues; ParameterDiscreteValue crParameterDiscreteValue; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.DropDownList DropDownList1; protected System.Web.UI.WebControls.Button Button1; ConnectionInfo crConnectionInfo;
private void Page_Load(object sender, System.EventArgs e) { try { this.setExportOptions(); this.prepareReport(); } catch (Exception ex) { Label1.Text = ex.ToString(); Label1.Visible = true; } }
#region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load);
} #endregion private void setExportOptions() { // ******************************************* // Initialize Dropdownlist for Format types // ******************************************* DropDownList1.Items.Add(""); DropDownList1.Items.Add("Rich Text (RTF)"); DropDownList1.Items.Add("Portable Document (PDF)"); DropDownList1.Items.Add("MS Word (DOC)"); DropDownList1.Items.Add("MS Excel (XLS)"); DropDownList1.Items.Add("Crystal Report (RPT)"); DropDownList1.Items.Add("HTML 3.2 (HTML)"); DropDownList1.Items.Add("HTML 4.0 (HTML)"); } private void prepareReport() { crReportDocument = new ReportDocument();
crReportDocument.Load("c:\\inetpub\\wwwroot\\hopeandhome\\reports\\Month lyAc counting.rpt",CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempC opy) ; crDatabase = crReportDocument.Database; crTables = crDatabase.Tables;
crConnectionInfo = new ConnectionInfo(); crConnectionInfo.ServerName = "HopeAndHome"; crConnectionInfo.DatabaseName = "HopeAndHome"; crConnectionInfo.UserID = "user"; crConnectionInfo.Password = "password";
foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in crTables) { crTableLogOnInfo = aTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectionInfo; aTable.ApplyLogOnInfo(crTableLogOnInfo); }
CrystalReportViewer1.ReportSource = crReportDocument;
crParameterFields = CrystalReportViewer1.ParameterFieldInfo; crParameterField = crParameterFields["@AccStartDate"]; crParameterValues = crParameterField.CurrentValues; crParameterDiscreteValue = new ParameterDiscreteValue(); crParameterDiscreteValue.Value = "6/30/2002"; crParameterValues.Add(crParameterDiscreteValue);
crParameterField = crParameterFields["@AccEndDate"]; crParameterValues = crParameterField.CurrentValues; crParameterDiscreteValue = new ParameterDiscreteValue(); crParameterDiscreteValue.Value = "7/31/2002"; crParameterValues.Add(crParameterDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo = crParameterFields; } private void ExportReport() { // This subroutine uses a case statement to determine the selected export format from the dropdownlist // menu and then sets the appropriate export options for the selected export format. The report is // exported to a subdirectory called "Exported".
// ******************************** //Check to see if the application directory has a subdirectory called "Exported". //If not, create the directory since exported files will be placed here. //This uses the Directory class of the System.IO namespace. string ExportPath; //ExportPath = Request.PhysicalApplicationPath + "Exported\\"; //if (Directory.Exists(ExportPath) == false) Directory.CreateDirectory(Request.PhysicalApplicationPath + "Exported\\"); ExportPath = @"\HopeAndHome\Upload\"; // ********************************
// First we must create a new instance of the diskfiledestinationoptions class and // set variable called crExportOptions to the exportoptions class of the reportdocument. crDiskFileDestinationOptions = new DiskFileDestinationOptions(); crExportOptions = crReportDocument.ExportOptions;
//Find the export type specified in the dropdownlist and export the report. The possible export format //types are Rich Text(RTF), Portable Document (PDF), MS Word (DOC), MS Excel (XLS), Crystal Report (RPT), //HTML 3.2 (HTML) and HTML 4.0 (HTML) // //Though not used in this sample application, there are options that can be specified for various format types. //When exporting to Rich Text, Word, or PDF, you can use the PdfRtfWordFormatOptions class to specify the //first page, last page or page range to be exported. //When exporting to Excel, you can use the ExcelFormatOptions class to specify export properties such as //the column width etc.
if (DropDownList1.SelectedItem.Text == "Rich Text (RTF)") { //-------------------------------------------------------------------- //Export to RTF.
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class crDiskFileDestinationOptions.DiskFileName = ExportPath + "RichTextFormat.rtf";
//set the required report ExportOptions properties crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.RichText; crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "Portable Document (PDF)") { //-------------------------------------------------------------------- //Export to PDF
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class crDiskFileDestinationOptions.DiskFileName = ExportPath + "PortableDoc.pdf";
//set the required report ExportOptions properties crExportOptions.DestinationOptions = crDiskFileDestinationOptions; crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "MS Word (DOC)") { //-------------------------------------------------------------------- //Export to Word
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class crDiskFileDestinationOptions.DiskFileName = ExportPath + "Word.doc";
//set the required report ExportOptions properties crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.WordForWindows; crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "MS Excel (XLS)") { //-------------------------------------------------------------------- //Export to Excel
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class crDiskFileDestinationOptions.DiskFileName = ExportPath + "Excel.xls";
//set the required report ExportOptions properties crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.Excel; crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "Crystal Report (RPT)") { //-------------------------------------------------------------------- //Export to Crystal reports:
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class crDiskFileDestinationOptions.DiskFileName = ExportPath + "Report.rpt";
//set the required report ExportOptions properties crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.CrystalReport; crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "HTML 3.2 (HTML)") { //-------------------------------------------------------------------- //Export to HTML32:
HTMLFormatOptions HTML32Formatopts = new HTMLFormatOptions();
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.HTML32;
HTML32Formatopts.HTMLBaseFolderName = ExportPath + "Html32Folder"; //Foldername to place HTML files HTML32Formatopts.HTMLFileName = "HTML32.html"; HTML32Formatopts.HTMLEnableSeparatedPages = false; HTML32Formatopts.HTMLHasPageNavigator = false;
crExportOptions.FormatOptions = HTML32Formatopts; //-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "HTML 4.0 (HTML)") { //-------------------------------------------------------------------- //Export to Html 4.0:
HTMLFormatOptions HTML40Formatopts = new HTMLFormatOptions();
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.HTML40;
HTML40Formatopts.HTMLBaseFolderName = ExportPath + "Html40Folder"; // Foldername to place HTML files HTML40Formatopts.HTMLFileName = "HTML40.html"; HTML40Formatopts.HTMLEnableSeparatedPages = true; HTML40Formatopts.HTMLHasPageNavigator = true; HTML40Formatopts.FirstPageNumber = 1; HTML40Formatopts.LastPageNumber = 3;
crExportOptions.FormatOptions = HTML40Formatopts; } //export format
//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 crReportDocument.Export(); } catch (Exception err) { Response.Write("<BR>"); Response.Write(err.Message.ToString()); } }
private void Button1_Click(object sender, System.EventArgs e) { this.prepareReport(); this.ExportReport(); } } }
| [ngfx-crystal] member Click here to reveal e-mail address = YOUR ID | http://www.aspfriends.com/aspfriends/ngfx-crystal.asp = JOIN/QUIT
|
|
| |
|
| |
| Wolfgang Baeck |
Tim,
I get no error, just no export. By the way, where should I call crReportDocument.Close()? After export or where else?
Also, the export method is the exact copy of the sample provided by Crystal Decisions.
Wolfgang
-----Original Message----- From: Tim Musschoot [mailto:Click here to reveal e-mail address] Sent: Wednesday, August 14, 2002 6:01 PM To: ngfx-crystal Subject: [ngfx-crystal] RE: Unable to export a report
What kind of error ?
You forgot to call
crReportDocument.Close(); crReportDoucment = null; // not really necessairy !
Tim Musschoot Software Engineer AspFriends Moderation Team Click here to reveal e-mail address http://www.aspalliance.com/timmusschoot
-----Oorspronkelijk bericht----- Van: Wolfgang Baeck [mailto:Click here to reveal e-mail address] Verzonden: woensdag 14 augustus 2002 18:33 Aan: ngfx-crystal Onderwerp: [ngfx-crystal] Unable to export a report
Hi,
I implemented the export sample from CR and my report never exports to my server. I don't get an error, there is just nothing there in the directory or any other directory for that matter. Any Idea? Attached is my source.
Wolfgang
using System; using System.IO; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using CrystalDecisions.Shared; using CrystalDecisions.CrystalReports.Engine;
namespace HopeAndHome.Admin { public class AccForPeriod : System.Web.UI.Page { protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1; // CR variables ReportDocument crReportDocument; ExportOptions crExportOptions; DiskFileDestinationOptions crDiskFileDestinationOptions; Database crDatabase; Tables crTables; TableLogOnInfo crTableLogOnInfo; ParameterFields crParameterFields; ParameterField crParameterField; ParameterValues crParameterValues; ParameterDiscreteValue crParameterDiscreteValue; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.DropDownList DropDownList1; protected System.Web.UI.WebControls.Button Button1; ConnectionInfo crConnectionInfo;
private void Page_Load(object sender, System.EventArgs e) { try { this.setExportOptions(); this.prepareReport(); } catch (Exception ex) { Label1.Text = ex.ToString(); Label1.Visible = true; } }
#region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load);
} #endregion private void setExportOptions() { // ******************************************* // Initialize Dropdownlist for Format types // ******************************************* DropDownList1.Items.Add(""); DropDownList1.Items.Add("Rich Text (RTF)"); DropDownList1.Items.Add("Portable Document (PDF)"); DropDownList1.Items.Add("MS Word (DOC)"); DropDownList1.Items.Add("MS Excel (XLS)"); DropDownList1.Items.Add("Crystal Report (RPT)"); DropDownList1.Items.Add("HTML 3.2 (HTML)"); DropDownList1.Items.Add("HTML 4.0 (HTML)"); } private void prepareReport() { crReportDocument = new ReportDocument();
crReportDocument.Load("c:\\inetpub\\wwwroot\\hopeandhome\\reports\\Month lyAc counting.rpt",CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempC opy) ; crDatabase = crReportDocument.Database; crTables = crDatabase.Tables;
crConnectionInfo = new ConnectionInfo(); crConnectionInfo.ServerName = "HopeAndHome"; crConnectionInfo.DatabaseName = "HopeAndHome"; crConnectionInfo.UserID = "user"; crConnectionInfo.Password = "password";
foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in crTables) { crTableLogOnInfo = aTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectionInfo; aTable.ApplyLogOnInfo(crTableLogOnInfo); }
CrystalReportViewer1.ReportSource = crReportDocument;
crParameterFields = CrystalReportViewer1.ParameterFieldInfo; crParameterField = crParameterFields["@AccStartDate"]; crParameterValues = crParameterField.CurrentValues; crParameterDiscreteValue = new ParameterDiscreteValue(); crParameterDiscreteValue.Value = "6/30/2002"; crParameterValues.Add(crParameterDiscreteValue);
crParameterField = crParameterFields["@AccEndDate"]; crParameterValues = crParameterField.CurrentValues; crParameterDiscreteValue = new ParameterDiscreteValue(); crParameterDiscreteValue.Value = "7/31/2002"; crParameterValues.Add(crParameterDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo = crParameterFields; } private void ExportReport() { // This subroutine uses a case statement to determine the selected export format from the dropdownlist // menu and then sets the appropriate export options for the selected export format. The report is // exported to a subdirectory called "Exported".
// ******************************** //Check to see if the application directory has a subdirectory called "Exported". //If not, create the directory since exported files will be placed here. //This uses the Directory class of the System.IO namespace. string ExportPath; //ExportPath = Request.PhysicalApplicationPath + "Exported\\"; //if (Directory.Exists(ExportPath) == false) Directory.CreateDirectory(Request.PhysicalApplicationPath + "Exported\\"); ExportPath = @"\HopeAndHome\Upload\"; // ********************************
// First we must create a new instance of the diskfiledestinationoptions class and // set variable called crExportOptions to the exportoptions class of the reportdocument. crDiskFileDestinationOptions = new DiskFileDestinationOptions(); crExportOptions = crReportDocument.ExportOptions;
//Find the export type specified in the dropdownlist and export the report. The possible export format //types are Rich Text(RTF), Portable Document (PDF), MS Word (DOC), MS Excel (XLS), Crystal Report (RPT), //HTML 3.2 (HTML) and HTML 4.0 (HTML) // //Though not used in this sample application, there are options that can be specified for various format types. //When exporting to Rich Text, Word, or PDF, you can use the PdfRtfWordFormatOptions class to specify the //first page, last page or page range to be exported. //When exporting to Excel, you can use the ExcelFormatOptions class to specify export properties such as //the column width etc.
if (DropDownList1.SelectedItem.Text == "Rich Text (RTF)") {
//-------------------------------------------------------------------- //Export to RTF.
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "RichTextFormat.rtf";
//set the required report ExportOptions properties crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.RichText; crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "Portable Document (PDF)") {
//-------------------------------------------------------------------- //Export to PDF
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "PortableDoc.pdf";
//set the required report ExportOptions properties crExportOptions.DestinationOptions = crDiskFileDestinationOptions; crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "MS Word (DOC)") {
//-------------------------------------------------------------------- //Export to Word
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Word.doc";
//set the required report ExportOptions properties crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.WordForWindows; crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "MS Excel (XLS)") {
//-------------------------------------------------------------------- //Export to Excel
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Excel.xls";
//set the required report ExportOptions properties crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.Excel; crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "Crystal Report (RPT)") {
//-------------------------------------------------------------------- //Export to Crystal reports:
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Report.rpt";
//set the required report ExportOptions properties crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.CrystalReport; crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "HTML 3.2 (HTML)") {
//-------------------------------------------------------------------- //Export to HTML32:
HTMLFormatOptions HTML32Formatopts = new HTMLFormatOptions();
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.HTML32;
HTML32Formatopts.HTMLBaseFolderName = ExportPath + "Html32Folder"; //Foldername to place HTML files HTML32Formatopts.HTMLFileName = "HTML32.html";
HTML32Formatopts.HTMLEnableSeparatedPages = false; HTML32Formatopts.HTMLHasPageNavigator = false;
crExportOptions.FormatOptions = HTML32Formatopts;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "HTML 4.0 (HTML)") {
//-------------------------------------------------------------------- //Export to Html 4.0:
HTMLFormatOptions HTML40Formatopts = new HTMLFormatOptions();
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.HTML40;
HTML40Formatopts.HTMLBaseFolderName = ExportPath + "Html40Folder"; // Foldername to place HTML files HTML40Formatopts.HTMLFileName = "HTML40.html";
HTML40Formatopts.HTMLEnableSeparatedPages = true; HTML40Formatopts.HTMLHasPageNavigator = true; HTML40Formatopts.FirstPageNumber = 1; HTML40Formatopts.LastPageNumber = 3;
crExportOptions.FormatOptions = HTML40Formatopts; } //export format
//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 crReportDocument.Export(); } catch (Exception err) { Response.Write("<BR>"); Response.Write(err.Message.ToString()); } }
private void Button1_Click(object sender, System.EventArgs e) { this.prepareReport(); this.ExportReport(); } } }
| [ngfx-crystal] member Click here to reveal e-mail address = YOUR ID | http://www.aspfriends.com/aspfriends/ngfx-crystal.asp = JOIN/QUIT
| [ngfx-crystal] member Click here to reveal e-mail address = YOUR ID | http://www.aspfriends.com/aspfriends/ngfx-crystal.asp = JOIN/QUIT
|
|
| |
|
| |
| Tim Musschoot |
The close method is imperative! I couldn't get it to work without it ! (dito problem: no export). You must place it after the 'export' call.
Tim Musschoot Software Engineer AspFriends Moderation Team Click here to reveal e-mail address http://www.aspalliance.com/timmusschoot
-----Oorspronkelijk bericht----- Van: Wolfgang Baeck [mailto:Click here to reveal e-mail address] Verzonden: donderdag 15 augustus 2002 5:07 Aan: ngfx-crystal Onderwerp: [ngfx-crystal] RE: Unable to export a report
Tim,
I get no error, just no export. By the way, where should I call crReportDocument.Close()? After export or where else?
Also, the export method is the exact copy of the sample provided by Crystal Decisions.
Wolfgang
-----Original Message----- From: Tim Musschoot [mailto:Click here to reveal e-mail address] Sent: Wednesday, August 14, 2002 6:01 PM To: ngfx-crystal Subject: [ngfx-crystal] RE: Unable to export a report
What kind of error ?
You forgot to call
crReportDocument.Close(); crReportDoucment = null; // not really necessairy !
Tim Musschoot Software Engineer AspFriends Moderation Team Click here to reveal e-mail address http://www.aspalliance.com/timmusschoot
-----Oorspronkelijk bericht----- Van: Wolfgang Baeck [mailto:Click here to reveal e-mail address] Verzonden: woensdag 14 augustus 2002 18:33 Aan: ngfx-crystal Onderwerp: [ngfx-crystal] Unable to export a report
Hi,
I implemented the export sample from CR and my report never exports to my server. I don't get an error, there is just nothing there in the directory or any other directory for that matter. Any Idea? Attached is my source.
Wolfgang
using System; using System.IO; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using CrystalDecisions.Shared; using CrystalDecisions.CrystalReports.Engine;
namespace HopeAndHome.Admin { public class AccForPeriod : System.Web.UI.Page { protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1; // CR variables ReportDocument crReportDocument; ExportOptions crExportOptions; DiskFileDestinationOptions crDiskFileDestinationOptions; Database crDatabase; Tables crTables; TableLogOnInfo crTableLogOnInfo; ParameterFields crParameterFields; ParameterField crParameterField; ParameterValues crParameterValues; ParameterDiscreteValue crParameterDiscreteValue; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.DropDownList DropDownList1; protected System.Web.UI.WebControls.Button Button1; ConnectionInfo crConnectionInfo;
private void Page_Load(object sender, System.EventArgs e) { try { this.setExportOptions(); this.prepareReport(); } catch (Exception ex) { Label1.Text = ex.ToString(); Label1.Visible = true; } }
#region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load);
} #endregion private void setExportOptions() { // ******************************************* // Initialize Dropdownlist for Format types // ******************************************* DropDownList1.Items.Add(""); DropDownList1.Items.Add("Rich Text (RTF)"); DropDownList1.Items.Add("Portable Document (PDF)"); DropDownList1.Items.Add("MS Word (DOC)"); DropDownList1.Items.Add("MS Excel (XLS)"); DropDownList1.Items.Add("Crystal Report (RPT)"); DropDownList1.Items.Add("HTML 3.2 (HTML)"); DropDownList1.Items.Add("HTML 4.0 (HTML)"); } private void prepareReport() { crReportDocument = new ReportDocument();
crReportDocument.Load("c:\\inetpub\\wwwroot\\hopeandhome\\reports\\Month lyAc counting.rpt",CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempC opy) ; crDatabase = crReportDocument.Database; crTables = crDatabase.Tables;
crConnectionInfo = new ConnectionInfo(); crConnectionInfo.ServerName = "HopeAndHome"; crConnectionInfo.DatabaseName = "HopeAndHome"; crConnectionInfo.UserID = "user"; crConnectionInfo.Password = "password";
foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in crTables) { crTableLogOnInfo = aTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectionInfo; aTable.ApplyLogOnInfo(crTableLogOnInfo); }
CrystalReportViewer1.ReportSource = crReportDocument;
crParameterFields = CrystalReportViewer1.ParameterFieldInfo; crParameterField = crParameterFields["@AccStartDate"]; crParameterValues = crParameterField.CurrentValues; crParameterDiscreteValue = new ParameterDiscreteValue(); crParameterDiscreteValue.Value = "6/30/2002"; crParameterValues.Add(crParameterDiscreteValue);
crParameterField = crParameterFields["@AccEndDate"]; crParameterValues = crParameterField.CurrentValues; crParameterDiscreteValue = new ParameterDiscreteValue(); crParameterDiscreteValue.Value = "7/31/2002"; crParameterValues.Add(crParameterDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo = crParameterFields; } private void ExportReport() { // This subroutine uses a case statement to determine the selected export format from the dropdownlist // menu and then sets the appropriate export options for the selected export format. The report is // exported to a subdirectory called "Exported".
// ******************************** //Check to see if the application directory has a subdirectory called "Exported". //If not, create the directory since exported files will be placed here. //This uses the Directory class of the System.IO namespace. string ExportPath; //ExportPath = Request.PhysicalApplicationPath + "Exported\\"; //if (Directory.Exists(ExportPath) == false) Directory.CreateDirectory(Request.PhysicalApplicationPath + "Exported\\"); ExportPath = @"\HopeAndHome\Upload\"; // ********************************
// First we must create a new instance of the diskfiledestinationoptions class and // set variable called crExportOptions to the exportoptions class of the reportdocument. crDiskFileDestinationOptions = new DiskFileDestinationOptions(); crExportOptions = crReportDocument.ExportOptions;
//Find the export type specified in the dropdownlist and export the report. The possible export format //types are Rich Text(RTF), Portable Document (PDF), MS Word (DOC), MS Excel (XLS), Crystal Report (RPT), //HTML 3.2 (HTML) and HTML 4.0 (HTML) // //Though not used in this sample application, there are options that can be specified for various format types. //When exporting to Rich Text, Word, or PDF, you can use the PdfRtfWordFormatOptions class to specify the //first page, last page or page range to be exported. //When exporting to Excel, you can use the ExcelFormatOptions class to specify export properties such as //the column width etc.
if (DropDownList1.SelectedItem.Text == "Rich Text (RTF)") {
//-------------------------------------------------------------------- //Export to RTF.
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "RichTextFormat.rtf";
//set the required report ExportOptions properties crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.RichText; crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "Portable Document (PDF)") {
//-------------------------------------------------------------------- //Export to PDF
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "PortableDoc.pdf";
//set the required report ExportOptions properties crExportOptions.DestinationOptions = crDiskFileDestinationOptions; crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "MS Word (DOC)") {
//-------------------------------------------------------------------- //Export to Word
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Word.doc";
//set the required report ExportOptions properties crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.WordForWindows; crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "MS Excel (XLS)") {
//-------------------------------------------------------------------- //Export to Excel
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Excel.xls";
//set the required report ExportOptions properties crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.Excel; crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "Crystal Report (RPT)") {
//-------------------------------------------------------------------- //Export to Crystal reports:
//append a filename to the export path and set this file as the filename property for //the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Report.rpt";
//set the required report ExportOptions properties crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.CrystalReport; crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "HTML 3.2 (HTML)") {
//-------------------------------------------------------------------- //Export to HTML32:
HTMLFormatOptions HTML32Formatopts = new HTMLFormatOptions();
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.HTML32;
HTML32Formatopts.HTMLBaseFolderName = ExportPath + "Html32Folder"; //Foldername to place HTML files HTML32Formatopts.HTMLFileName = "HTML32.html";
HTML32Formatopts.HTMLEnableSeparatedPages = false; HTML32Formatopts.HTMLHasPageNavigator = false;
crExportOptions.FormatOptions = HTML32Formatopts;
//-------------------------------------------------------------------- } else if (DropDownList1.SelectedItem.Text == "HTML 4.0 (HTML)") {
//-------------------------------------------------------------------- //Export to Html 4.0:
HTMLFormatOptions HTML40Formatopts = new HTMLFormatOptions();
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; crExportOptions.ExportFormatType = ExportFormatType.HTML40;
HTML40Formatopts.HTMLBaseFolderName = ExportPath + "Html40Folder"; // Foldername to place HTML files HTML40Formatopts.HTMLFileName = "HTML40.html";
HTML40Formatopts.HTMLEnableSeparatedPages = true; HTML40Formatopts.HTMLHasPageNavigator = true; HTML40Formatopts.FirstPageNumber = 1; HTML40Formatopts.LastPageNumber = 3;
crExportOptions.FormatOptions = HTML40Formatopts; } //export format
//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 crReportDocument.Export(); } catch (Exception err) { Response.Write("<BR>"); Response.Write(err.Message.ToString()); } }
private void Button1_Click(object sender, System.EventArgs e) {   | | |