C1ReportViewer - Avoid Print Dialogue

Originally Posted 14 March 2014, 12:28 pm EST

  • Originally Posted 14 March 2014, 12:28 pm EST

    Hello,

    I am using the ReportViewer to display reports in my ASP.Net Web Application. (Version 2.6.20123.54608)

    My users are requesting for removal of the dialogue box after they click on print button in the preview. How do I avoid showing the dialogue box and send the report directly to the default printer? Is there a way I can avoid the preview as well.

    This is my code:

    C1.C1Report.C1Report C1Report1 = new C1.C1Report.C1Report();
    //load report xml which is created using xsd file
    C1Report1.Load(Server.MapPath("~/xml/C1Receipt.xml"), "Rpt_Receipt");
    //Name of xsd file
    C1Report1.DataSource.ConnectionString = Server.MapPath("~/xml/ReceiptPrint1.xsd");
    //Table name
    C1Report1.DataSource.RecordSource = "ReceiptPrint";
    //Save report xml after changing connection string and recordsource
    C1Report1.Save(Server.MapPath("~/xml/ReceiptPrint1.xml"));
    //Bind xml file with ReportViewer
    C1ReportViewer1.FileName = "~/xml/ReceiptPrint1.xml";
    C1ReportViewer1.ReportName = "Rpt_Receipt";


    Thanks in Advance,

    Alhad
  • Reply

    Hello,

    There is not a direct way to hide the Print dialog, so I would suggest you to customize the toolbar to remove the default print button on the toolbar. This would avoid the display of the print dialog and even the preview. Please refer to the following demo sample that describes how you can customize the toolbar.

    Later, you can add a new custom button, and handle its client side click event to perform a postback to the server side using the _doPostback. On the server side you can generate a C1Report instance from C1ReportViewer and call the print method of C1Report to print the report. Here is the sample code for the print method:


    public void Print()
    {
    C1Report rpt = C1ReportViewer.CreateC1Report();
    rpt.ReportDefinition = "~/CommonTasks.xml";
    rpt.ReportName = "01: Alternating Background (Greenbar report)";
    rpt.Print();
    }


    Hope it helps.

    Thanks,
    Manpreet Kaur
  • Reply

    @manpreetkaur said:
    Hello,

    ...

    Later, you can add a new custom button, ...


    public void Print()
    {
    C1Report rpt = C1ReportViewer.CreateC1Report();
    rpt.ReportDefinition = "~/CommonTasks.xml";
    rpt.ReportName = "01: Alternating Background (Greenbar report)";
    rpt.Print();
    }




    ...


    HI

    Run C1Report.Print() in server side ? the c# code was run at server side, I think the report would be printed in Server's printer.
    please provide the right solution(print the report to client's printer).

    Best regards

    Chris
  • Reply

    Hello Chris,

    Please refer to the attached sample where you can print without preview in C1ReportViewer.

    Thanks,
    Richa
    2014/04/C1ReportViewerPrintWithoutPreview.zip
  • Reply

    Hello Richa,

    When I tried to use the code in the sample, I get the following error

    System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

    Also, what I am looking for is to print a report directly without previewing it. e.g. if the user is viewing a list of invoices and wants to print a particular invoice for a duplicate copy, he does not want to see the preview, just take a print.

    Your solution shows that I have to use the C1ReportViewer anyway. So what the user will save is 2 clicks of the print dialogue after clicking on print in the report viewer. I want to know if there is a way to print the report without previewing it at all.

    Regards,

    Alhad
  • Reply

    Hello Alhad,

    If you wish to just render the report and print it without loading it in C1ReportViewer, then I would suggest you use C1Report class and use the following code :
    C1Report rpt = new C1Report();
    rpt.Load("FileName", "ReportName");
    rpt.Render();
    PrinterSettings ps = new PrinterSettings();
    ps.PrintToFile = true;
    rpt.Print(ps, false);


    Let me know if this works for you.

    Thanks,
    Richa
  • Reply

    Hello Richa,

    When I try to use the code you have given, the compiler gives the following message for the rpt.Print command, in the code window:

    C1.C1Report.C1Report does not contain a definition for Print and no extension method 'Print' accepting a first argument C1.C1Report.C1Report could be found (are you missing a using directive or an assembly reference)

    If I remove the line, nothing happens when I run the code. I am using version 2.6.20123.54608. Does this have anything to do with the message?

    Regards,

    Alhad
  • Marked as Answer

    Reply

    Hello Alhad,

    You need to add reference to C1Report assembly to use this method. Please add reference to C1.C1Report.2.dll in your project.

    Thanks,
    Richa
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels