2351946 - CR for VS .net CopyFrom does not use PaperSource ( Tray )

SAP Knowledge Base Article - Public

2351946 - CR for VS .net CopyFrom does not use PaperSource ( Tray )

Symptom

Using Crystal Reports for Visual Studio SP 17 CopyFrom() when using either the Engine or RAS the PaperSource ( Tray ) is not updated and defaults to the Printers default paper tray.

Reproducing the Issue

Create a simple .NET app to copy the Printer info from the Printer into the report properties. Watch the PaperSource property, always defaults to what the default value is for the printer:

private void btrCopyFrom_Click(object sender, EventArgs e)
{
    System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument();
    CrystalDecisions.Shared.PrintLayoutSettings PrintLayout = new CrystalDecisions.Shared.PrintLayoutSettings();
    System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
    System.Drawing.Printing.PageSettings crPage = new System.Drawing.Printing.PageSettings();

    printerSettings.PrinterName = cboCurrentPrinters.SelectedItem.ToString();

    System.Drawing.Printing.PageSettings pageSettings = new System.Drawing.Printing.PageSettings(printerSettings);
    //System.Drawing.Printing.PageSettings pageSettings = cboCurrentPrinters.SelectedIndex.

    //MessageBox.Show("Bottom: " + pageSettings.Margins.Bottom.ToString() + "\nTop: " + pageSettings.Margins.Top.ToString() + "\nLeft: " + pageSettings.Margins.Left.ToString() + "\nRight: " + pageSettings.Margins.Right.ToString());

    //printerSettings.DefaultPageSettings.PrinterSettings.PrinterName = "SATO CG212"; // EPSON LQ-590 ESC/P 2 Ver 2.0   SATO CG212   Argox X-3200 PPLB

    //pageSettings.Margins.Left = 0;
    //pageSettings.Margins.Right = 0;
    //pageSettings.Margins.Top = 0;
    //pageSettings.Margins.Bottom = 0;

    if (chkDissociate.Checked == true)
        rpt.PrintOptions.DissociatePageSizeAndPrinterPaperSize = true;
    else
        rpt.PrintOptions.DissociatePageSizeAndPrinterPaperSize = false;


    if (chkbxCurrentColour.Checked)
    {
        printerSettings.DefaultPageSettings.Color = true;
        pageSettings.Color = true;
    }
    else
    {
        printerSettings.DefaultPageSettings.Color = false;
        pageSettings.Color = false;
    }

    //MessageBox.Show("Will perform CopyFrom...", this.Text);

    string MySTRTemp = cboCurrentPaperSizes.SelectedItem.ToString();
    int MyENUM = 0;
    int MyENUM1 = 0;

    if (cboCurrentPaperTrays.SelectedItem != null)
    {
        string MyPaperSource = cboCurrentPaperTrays.SelectedItem.ToString();
        MySTRTemp = cboCurrentPaperTrays.SelectedItem.ToString();
        MyENUM = MySTRTemp.LastIndexOf(@":");
        MySTRTemp = cboCurrentPaperTrays.Text.Substring(0, MyENUM);
        //crPage.PaperSource.Kind = PaperSourceKind.
    }

    // this will return false if enum cannot be converted
    bool myNum = Int32.TryParse(MySTRTemp, out MyENUM1);
    // bug in API - fix slated for SP 18
    printerSettings.DefaultPageSettings.PaperSource.RawKind = (int)MyENUM1; //"Tray 4"; //

    try
    {
        rpt.PrintOptions.CopyFrom(printerSettings, pageSettings);
    }
    catch (Exception ex)
    {
        btnSQLStatement.Text += "\nError: " + ex.Message.ToString() + "\n";
    }

    try
    {
        printerSettings.FromPage = 1;
        printerSettings.ToPage = 1;
        //PrintLayout.Scaling = PrintLayoutSettings.PrintScaling.Scale;

        pageSettings.PrinterSettings.FromPage = 1;
        pageSettings.PrinterSettings.ToPage = 1;
        pageSettings.PrinterSettings.PrintRange = PrintRange.SomePages;

        rpt.PrintToPrinter(printerSettings, pageSettings, false, PrintLayout);
    }
    catch (Exception ex)
    {
        MessageBox.Show("ERROR: " + ex.Message);
        return;
    }
}

Resolution

This issue has been escalated to R&D for a fix.

Should be released in SP 17 due out end of September, 2016 if all goes well

Keywords

CopyFrom, cr for VS, .net. , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , Problem

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio