3 weeks ago
You can use Crystal Reports for Visual Studio, download from here:
https://help.sap.com/docs/SUPPORT_CONTENT/crystalreports/3354091173.html
See my blog on converting/upgrading your previous app to current SP 35 runtime:
Here's a sample app I created for setting logon info etc.
how-to-parameters-in-crystal-reports-for-visual-studio-net
You can use the same code in a WEB app, of course you'll have to change the messageboxes to Reponse messages.
The rest of it should convert to a WEB app.
Here's a test app that uses local printers etc.
You should be able to create a new WEB project, add a default.aspx and past in this code: This system won't allow attaching zip file so hopefully this will help.
using System;
using System.IO;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.ReportDefModel;
using CrystalDecisions.ReportAppServer.CommonControls;
using CrystalDecisions.ReportAppServer.CommLayer;
using CrystalDecisions.ReportAppServer.CommonObjectModel;
using CrystalDecisions.ReportAppServer.ObjectFactory;
using CrystalDecisions.ReportAppServer.Prompting;
using CrystalDecisions.ReportAppServer.DataSetConversion;
using CrystalDecisions.ReportAppServer.DataDefModel;
using CrystalDecisions.Web;
using System.Collections.Generic;
using System.Drawing.Printing;
public partial class _Default : System.Web.UI.Page
{
CrystalDecisions.CrystalReports.Engine.ReportDocument rd;
CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;
protected void Page_Init(object sender, EventArgs e)
{
System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument();
rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
if (Page.IsPostBack == false)
{
//cboCurrentPaperSizes.Items.Clear();
//cboCurrentPaperTrays.Items.Clear();
try
{
if (System.Drawing.Printing.PrinterSettings.InstalledPrinters.Count > 0)
{
foreach (String myPrinter in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
cboCurrentPrinters.Items.Add(myPrinter);
}
cboCurrentPrinters.SelectedIndex = 0;
}
else
{
//rdoCurrent.Enabled = false;
//EnableDisableCurrentControls(false);
}
pDoc.PrinterSettings.PrinterName = this.cboCurrentPrinters.Text;
foreach (System.Drawing.Printing.PaperSize myPaperSize in pDoc.PrinterSettings.PaperSizes)
{
cboCurrentPaperSizes.Items.Add(myPaperSize.RawKind + ": " + myPaperSize.PaperName);
}
if (cboCurrentPaperSizes.Items.Count > 0)
{
cboCurrentPaperSizes.SelectedIndex = 0;
}
}
finally
{
// open the database connection
//myConnection.Close();
}
}
if (Page.IsPostBack == false)
{
try
{
//System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument();
pDoc.PrinterSettings.PrinterName = this.cboCurrentPrinters.Text;
foreach (System.Drawing.Printing.PaperSize myPaperSize in pDoc.PrinterSettings.PaperSizes)
{
cboCurrentPaperSizes.Items.Add(myPaperSize.RawKind + ": " + myPaperSize.PaperName);
}
if (cboCurrentPaperSizes.Items.Count > 0)
{
cboCurrentPaperSizes.SelectedIndex = 0;
}
}
finally
{
// open the database connection
//myConnection.Close();
}
}
//CrystalDecisions.CrystalReports.Engine.ReportDocument rd;
CrystalDecisions.CrystalReports.Engine.Database crDatabase;
CrystalDecisions.CrystalReports.Engine.Tables crTables;
CrystalDecisions.Shared.TableLogOnInfo tblogoninfo;
CrystalDecisions.Shared.ConnectionInfo cninfo;
//rd.Load(Server.MapPath("OLEDBProv.rpt"));
// ChartPIE
string url = "/inetpub/wwwroot/WebSite7VS2015/Classification Summary w Data.rpt"; //bo_ticket_reportdatei_small DonArgoxDefaultPrinter.rpt"; //PRCRMAEX(withData).rpt"; // "/inetpub/wwwroot/WebSite7/OfflinedVsWorked.rpt"; //Formulas ArgoxMaroonPSet 0176 CrystalReport1 LW450_TestDonSetNoDB ParameterOrder CortezSPs1 Formulas Chart shrinks in Viewer.rpt TS317-2014-Summary-DISCRETIONARY-CURRENT PERIOD
// Group Selection OLEDBProv Drill Down Group Level Hierarchical Grouping ReportWith10SubReport
rd.FileName = url;
rptClientDoc = rd.ReportClientDocument;
rptClientDoc.SummaryInfo.Title = "Don Test";
//rd.Load(url, OpenReportMethod.OpenReportByTempCopy);
//rptClientDoc = rd.ReportClientDocument;
#region Session
if (Session["rd"] == null)
{
try
{
rd.Load(url, OpenReportMethod.OpenReportByTempCopy);
rptClientDoc = (CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper)rd.ReportClientDocument;
Session.Add("rd", rptClientDoc.ReportSource);
CrystalDecisions.Shared.PrintLayoutSettings PrintLayout = new CrystalDecisions.Shared.PrintLayoutSettings();
CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions rptPRT = new CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions();
CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions rptPRTCloned = new CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions();
System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();
System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();
rptPRT = rptClientDoc.PrintOutputController.GetPrintOptions();
rptPRTCloned = rptPRT.Clone();
PrintLayout.Scaling = PrintLayoutSettings.PrintScaling.DoNotScale;
if (rptPRT.DriverName == "DISPLAY")
TextBox1.Text += "No Printer Checked\n";
//if (rd.PrintOptions.SavedPrinterName.Length != 0)
//{
// TextBox1.Text = "Saved Printer Name: " + rd.PrintOptions.SavedPrinterName.ToString() + "\n";
//}
//else
// TextBox1.Text = "Saved Printer Name: " + rptPRT.SavedPrinterName.ToString() + "\n";
TextBox1.Text += "Orientation: " + rd.PrintOptions.PaperOrientation.ToString() + "\n";
TextBox1.Text += "Paper Size: " + rptPRT.PaperSize.ToString() + "\n";
TextBox1.Text += "Left = " + (rptPRT.PageMargins.Left / 1440.0000).ToString();
TextBox1.Text += ": Right = " + (rptPRT.PageMargins.Right / 1440.0000).ToString();
TextBox1.Text += ": Top = " + (rptPRT.PageMargins.Top / 1440.0000).ToString();
TextBox1.Text += ": Bottom = " + (rptPRT.PageMargins.Bottom / 1440.0000).ToString();
//cninfo = new CrystalDecisions.Shared.ConnectionInfo();
////Name of server to which you want to change to runtime
//cninfo.ServerName = "VANN00517670A";
////Name of database to which you are changing
//cninfo.DatabaseName = "xtreme";
//cninfo.UserID = "sa";
//cninfo.Password = "1Oem2000";
//cninfo.IntegratedSecurity = false;
//crDatabase = rd.Database;
//crTables = crDatabase.Tables;
//foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in rd.Database.Tables)
//{
// // Get the TableLogOnInfo from the Table and then set the new ConnectionInfo values.
// tblogoninfo = crTable.LogOnInfo;
// tblogoninfo.ConnectionInfo = cninfo;
// // Apply the TableLogOnInfo
// crTable.ApplyLogOnInfo(tblogoninfo);
// // Set the location of the database. This value will vary from // database to database.
// //crTable.Location = crTable.Location; //"DATABASE.OWNER.TABLENAME";
//}
}
finally
{
// open the database connection
//myConnection.Close();
//rptClientDoc = rd.ReportClientDocument;
}
}
#endregion Session
CrystalReportViewer1.Height = 300;
CrystalReportViewer1.Width = 300;
CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
// set up the format export types:
int myFOpts = (int)(
CrystalDecisions.Shared.ViewerExportFormats.RptFormat |
CrystalDecisions.Shared.ViewerExportFormats.PdfFormat |
CrystalDecisions.Shared.ViewerExportFormats.RptrFormat |
//CrystalDecisions.Shared.ViewerExportFormats.XLSXFormat |
//CrystalDecisions.Shared.ViewerExportFormats.CsvFormat |
//CrystalDecisions.Shared.ViewerExportFormats.EditableRtfFormat |
//CrystalDecisions.Shared.ViewerExportFormats.ExcelRecordFormat |
//CrystalDecisions.Shared.ViewerExportFormats.RtfFormat |
//CrystalDecisions.Shared.ViewerExportFormats.WordFormat |
CrystalDecisions.Shared.ViewerExportFormats.XmlFormat |
CrystalDecisions.Shared.ViewerExportFormats.ExcelFormat |
//CrystalDecisions.Shared.ViewerExportFormats.AllFormats |
CrystalDecisions.Shared.ViewerExportFormats.ExcelRecordFormat);
//CrystalDecisions.Shared.ViewerExportFormats.NoFormat); // no exports allowed
//int myFOpts = (int)(CrystalDecisions.Shared.ViewerExportFormats.AllFormats);
CrystalReportViewer1.AllowedExportFormats = myFOpts;
//CrystalReportViewer1.HasPrintButton = false;
CrystalReportViewer1.ReportSource = Session["rd"];
//CrystalReportViewer1.ReportSource = rptClientDoc.ReportSource;
CrystalReportViewer1.EnableParameterPrompt = true;
CrystalReportViewer1.HasToggleParameterPanelButton = true;
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
try
{
System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument();
pDoc.PrinterSettings.PrinterName = this.cboCurrentPrinters.Text;
foreach (System.Drawing.Printing.PaperSize myPaperSize in pDoc.PrinterSettings.PaperSizes)
{
cboCurrentPaperSizes.Items.Add(myPaperSize.RawKind + ": " + myPaperSize.PaperName);
}
if (cboCurrentPaperSizes.Items.Count > 0)
{
cboCurrentPaperSizes.SelectedIndex = 0;
}
}
finally
{
// open the database connection
//myConnection.Close();
}
}
}
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument();
cboCurrentPaperSizes.Items.Clear();
pDoc.PrinterSettings.PrinterName = this.cboCurrentPrinters.Text;
foreach (System.Drawing.Printing.PaperSize myPaperSize in pDoc.PrinterSettings.PaperSizes)
{
cboCurrentPaperSizes.Items.Add(myPaperSize.RawKind + ": " + myPaperSize.PaperName);
}
if (cboCurrentPaperSizes.Items.Count > 0)
{
cboCurrentPaperSizes.SelectedIndex = 0;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
//Response.Redirect("http://localhost:64418/WebSite7/Default.aspx");
// THIS WORKS BUT IT DOESN'T UPDATE THE REPORT SETTINGS - No Printer to checked off
System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument();
System.Drawing.Printing.PageSettings page = new System.Drawing.Printing.PageSettings();
//page.PrinterSettings.Copies = 3;
CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions rasPROpts = new CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions();
CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions newOpts = new CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions();
CrystalDecisions.ReportAppServer.ReportDefModel.PageMargins crMarg = new CrystalDecisions.ReportAppServer.ReportDefModel.PageMargins();
CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions newOptsCloned = new CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions();
CrystalDecisions.Shared.PrintLayoutSettings PrintLayout = new CrystalDecisions.Shared.PrintLayoutSettings();
System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
newOpts.PrinterName = cboCurrentPrinters.SelectedItem.ToString();
string MySTRTemp = cboCurrentPaperSizes.SelectedItem.ToString();
int MyENUM = 0;
int MyENUM1 = 0;
string CRPaperSize;
// parse the enum values from the drop down list boxes
MyENUM = MySTRTemp.LastIndexOf(@":");
MySTRTemp = cboCurrentPaperSizes.Text.Substring(0, MyENUM);
// this will return false if enum cannot be converted
bool myNum = Int32.TryParse(MySTRTemp, out MyENUM1);
newOpts.PaperSize = (CrPaperSizeEnum)MyENUM1;
//newOpts.PaperSize = cboCurrentPaperSizes.SelectedIndex;
cboCurrentPaperSizes.Text = cboCurrentPaperSizes.SelectedItem.ToString();
//myPaperSize.PaperName.Text = CRPaperSize.Text;
// set the saved Paper Name
string savedPaperName = "";
//MySTRTemp = CRPaperSize.Text;
MyENUM = MySTRTemp.LastIndexOf(@":");
savedPaperName = MySTRTemp.Substring(MyENUM + 2);
newOpts.SavedPaperName = savedPaperName.ToString();
// this will return false if enum cannot be converted
myNum = Int32.TryParse(MySTRTemp, out MyENUM1);
newOpts.PaperSource = (CrPaperSourceEnum)MyENUM1;
// this info is saved in the RPT file
if (newOpts.PaperOrientation.ToString() != "crPaperOrientationPortrait")
{
rptClientDoc.PrintOutputController.ModifyPaperOrientation(CrPaperOrientationEnum.crPaperOrientationLandscape);
}
else
{
rptClientDoc.PrintOutputController.ModifyPaperOrientation(CrPaperOrientationEnum.crPaperOrientationPortrait);
}
//CRPrinterName.Text = newOpts.PrinterName;
// set custom paper size
// I don't recall why the constants below.... break reports now
//rptClientDoc.PrintOutputController.ModifyUserPaperSize(Convert.ToInt32((Double)1.248 * isMetric), Convert.ToInt32((Double)2.249 * isMetric));
try
{
//newOpts.PageContentWidth = 280000;
// set the printjon name as seen in spooler
//textBox1 = "Title: " + rpt.SummaryInfo.ReportTitle.ToString();
// this doesn't work , need to use RAS to change the name or set the summary info Title in CRD
//rpt.SummaryInfo.ReportTitle = "Overview Report RPT";
rptClientDoc.SummaryInfo.Title = "Overview Report RAS";
rptClientDoc.PrintOutputController.ModifyPrintOptions(newOpts);
}
catch (Exception ex)
{
Response.Write("ERROR: " + ex.Message);
return;
}
try
{
rptClientDoc.PrintOutputController.ModifyPrintOptions(newOpts);
}
catch (Exception ex)
{
Response.Write("ERROR: " + ex.Message);
return;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument();
CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions rasPROpts = new CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions();
CrystalDecisions.Shared.PrintLayoutSettings PrintLayout = new CrystalDecisions.Shared.PrintLayoutSettings();
CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions RASPO = new CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions();
CrystalDecisions.ReportAppServer.ReportDefModel.PageMargins crMarg = new CrystalDecisions.ReportAppServer.ReportDefModel.PageMargins();
pDoc.DefaultPageSettings.PrinterSettings.FromPage = 1;
pDoc.DefaultPageSettings.PrinterSettings.ToPage = 1;
rasPROpts.PrinterName = cboCurrentPrinters.Text;
// parse the enum values from the drop down list boxes and set the Paper tray
// Paper tray
string MySTRTemp = cboCurrentPaperSizes.SelectedItem.ToString();
int MyENUM = 0;
int MyENUM1 = 0;
// this will return false if enum cannot be converted
bool myNum = Int32.TryParse(MySTRTemp, out MyENUM1);
rasPROpts.PaperSource = (CrPaperSourceEnum)MyENUM1;
//rasPROpts.BinName = cboDefaultPaperTrays.SelectedText;
//rasPROpts.NumberOfCopies = 1;
//rasPROpts.AddPrinterPageRange(1, 1);
// this info is saved in the RPT file
if (RASPO.PaperOrientation.ToString() != "crPaperOrientationPortrait")
{
rptClientDoc.PrintOutputController.ModifyPaperOrientation(CrPaperOrientationEnum.crPaperOrientationLandscape);
}
else
{
rptClientDoc.PrintOutputController.ModifyPaperOrientation(CrPaperOrientationEnum.crPaperOrientationPortrait);
}
string MyRptName = rd.FileName.ToString();
MyRptName = MyRptName.Substring(MyRptName.LastIndexOf(@"\") + 1, (rd.FileName.Length - 3) - (MyRptName.LastIndexOf(@"\") + 2));
rasPROpts.JobTitle = MyRptName;
// using RAS to update the Printer properties
try
{
rptClientDoc.PrintOutputController.ModifyPrintOptions(RASPO);
}
catch (Exception ex)
{
Response.Write("ERROR: " + ex.Message);
return;
}
try
{
rptClientDoc.PrintOutputController.PrintReport(rasPROpts);
}
catch (Exception ex)
{
if (ex.Message == "Unable to start the print job. It may not be possible in the current security context.")
Response.Write("Users cancelled saving the print job to the file system");
else
Response.Write("ERROR: " + ex.Message);
return;
}
}
protected void Button3_Click(object sender, EventArgs e)
{
//CrystalDecisions.CrystalReports.Engine.ReportDocument rd;
//rd.Close();
}
protected void btrExpToStream_Click(object sender, EventArgs e)
{
//System.IO.Stream oStream;
//byte[] byteArray = null;
//string FileName = @"d:\atest\don"; // D:\Atest\Sharon Joy\Adv_Audit_Trail.rpt
//CrystalDecisions.CrystalReports.Engine.ReportDocument rd;
//oStream = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
////oStream = rd.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, FileName + ".pdf");
//byteArray = new byte[oStream.Length];
//oStream.Read(byteArray, 0, Convert.ToInt32(oStream.Length - 1));
//Response.ClearContent();
//Response.ClearHeaders();
//Response.ContentType = "application/pdf";
//Response.BinaryWrite(byteArray);
//Response.Flush();
//Response.Close();
}
}
To create a new WEB project start here:
Add a new WebForm:
Click on Design tab, lower left and in the Tool box if CR Viewer is not listed then add it by clicking on Choose Items...:
I just upgraded to Windows 11 and VS is crashing now so I have to re-install CR for VS and possibly VS 2022. Once I get it working I'll be back..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
67 | |
8 | |
8 | |
6 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.