0
votes

I need to know how to print Microsoft report(.rdlc) with ReportViewer Object without WinFrom from Consol Application? Is this way correct?

namespace ReportProntTset { public class Program {

        public static ReportViewer rp = new Microsoft.Reporting.WinForms.ReportViewer();

        static void Main(string[] args) {
        Start:
            Console.WriteLine("\nTo print picture one enter 0.\nFor second one enter any number.\n");
            int a = 0;
            string report = "";
            try {
                a = Convert.ToInt32(Console.ReadLine());
                if (a == 0) {
                    report = @"..\One.rdlc";
                }
                else {
                    report = @"..\Two.rdlc";
                }
                InitializeComponent(report);
                rp.Refresh();
                string ex = Print();
                if (ex != "") {
                    Console.WriteLine(ex);
                    goto Start;
                }
            }
            catch (Exception) {

                Console.WriteLine("Please Insert Right Charcter");
                goto Start;
            }
        }

        public static string Print() {
            string exa = "";
            try {
                rp.PrintDialog();
                rp.Clear();
                rp.LocalReport.ReleaseSandboxAppDomain();
            }
            catch (Exception ex) {

                exa = ex.Message;
            }
            return exa;
        }

        private static void InitializeComponent(string report) {
            Form fr = new Form();
            PrintDialog prDial = new System.Windows.Forms.PrintDialog();
            PrintDocument prDoc = new System.Drawing.Printing.PrintDocument();
            fr.SuspendLayout();

             //
             //pr
             //enter code here

            rp.LocalReport.ReportEmbeddedResource = report;
            rp.Location = new System.Drawing.Point(0, 0);
            rp.Name = "ViewReport";
            rp.Size = new System.Drawing.Size(0, 0);
            rp.TabIndex = 0;
            // 
            // prDial
            // `enter code here`
            prDial.UseEXDialog = true;
            // 
            // fr
            // 
            fr.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            fr.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            fr.ClientSize = new System.Drawing.Size(0, 0);
            fr.Controls.Add(rp);
            fr.Name = "ReportForm";
            fr.Text = "ImagePrint";
            fr.ResumeLayout(false);enter code here
        }
    }

}

Can U someone help me with that little issue. I believe there is few thing to add or change :)

1
Better to export this report to either pdf/image etc, and print this pdf/imageMarco Bong
Without using Windows Forms, where will you put ReportViewer?Hemal
@Hemal I do not know. DO is it necessary to use WinForm? Thanks in advanceVaxo
If you want to use ReportViewer, as you stated in your question, then Form is must.Hemal
You do not need ReportViewer to print report or export it into PDF, Excel or Word format. See here: msdn.microsoft.com/en-us/library/ms252091.aspxInitK

1 Answers

0
votes

Get the rendered contents and then you can do whatever:

var content = reportViewer.LocalReport.Render("PDF")