question

MohamedGADER-3104 avatar image
0 Votes"
MohamedGADER-3104 asked TimonYang-MSFT commented

Print automaticly serverReport

Hello
I have à winform with reportviwer control
I load server report in this control
I want to print it after loading report
Reportviewer1.refresh();
Thank you verry match.

dotnet-csharpsql-server-reporting-servicesdotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

TimonYang-MSFT avatar image
0 Votes"
TimonYang-MSFT answered TimonYang-MSFT commented

May I know where you are stuck now?

Do you not know how to load the data using the report viewer, or how to print it after loading?

In the first case, you can follow the steps below:

  1. Right click on the item => Add=> New Item => Report/Report Wizard.
    In my memory, this step before will only produce a blank Report, but now it includes all the steps to generate a DataSet to connect to the database.
    I'm not sure if my usage is wrong. The table produced in this way seems to have to include calculations. If we just want to display the current data, then we can delete the table produced in this step and add it by ourselves using the steps below.

  2. Add a DataSet.

    137954-11.png


  3. Add a table and add the required columns.

    137900-12.png

    137983-13.png

  4. Add Report Viewer to winform and bind the report we added as a data source.

If it is the second case, then we can use the while loop in the Task to determine the reportViewer1.CurrentStatus.CanPrint property.

         private void Form1_Load(object sender, EventArgs e)
         {
             this.ScoreTableTableAdapter.Fill(this.TestDataSet.ScoreTable);
             this.reportViewer1.RefreshReport();
    
             Task.Run(() =>
             {
                 while (true)
                 {
                     if (reportViewer1.CurrentStatus.CanPrint)
                     {
                         this.Invoke(new MethodInvoker(delegate
                         {
                             this.reportViewer1.PrintDialog();
                         }));
                         break;
                     }
                 }
             });
         }

If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


11.png (9.9 KiB)
12.png (5.1 KiB)
13.png (7.7 KiB)
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

hello,
i have a function to load reportViewer

            reportViewer1.ProcessingMode = ProcessingMode.Remote;   
             ServerReport serverReport = reportViewer1.ServerReport;
             NetworkCredential myCred = new NetworkCredential("administrateur", "***", "**");
             reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = myCred;
             reportViewer1.ServerReport.ReportServerUrl = new Uri(" some url");
             serverReport.ReportPath = "some path";
             ReportParameter p = new ReportParameter("id_retard", ((Saisie_Retard)f).tb_compteur.Text);
             ReportParameter p2 = new ReportParameter("quest", ((Saisie_Retard)f).quest);
             this.reportViewer1.ServerReport.SetParameters(new ReportParameter[] { p, p2 });
             reportViewer1.RefreshReport();

with your code i should select printer

but my objectif automatically justt after "reportViewer1.RefreshReport();" the report will be sended to default printer



0 Votes 0 ·

@MohamedGADER-3104
PrinterSettings Class may be helpful, we can use this class to set printing properties.
I don't have a printer, so I haven't tested it yet, you can try it.

      PrinterSettings printerSettings = new PrinterSettings();
      printerSettings.PrinterName = "";
      ......
      reportViewer1.PrinterSettings = printerSettings;
0 Votes 0 ·

hello
execuse me but the same problème,
May be i diden't put the code in the good place,

  reportViewer1.RefreshReport();
               
                
             Task.Run(() =>
             {
    
                 while (true)
                 {
    
                     if (reportViewer1.CurrentStatus.CanPrint)
                     {
                           
                         this.Invoke(new MethodInvoker(delegate
                         {
                             reportViewer1.PrintDialog();
    
                         }));
                         break;
    
                     }
                 }
             });


i put it before ,in or after the function TaskRun()?

0 Votes 0 ·

@MohamedGADER-3104
The RefreshReport() method must be placed before Task.Run. If placed in Task, the task will not end.
In theory, just put the relevant code of PrinterSettings before PrintDialog(). As for whether it is in Task, it should have no effect.
But I can't confirm it 100% because I don't have a printer to test.

0 Votes 0 ·

@MohamedGADER-3104
May I know whether your issue has been solved or not? If not, please share it in here. We can work together to figure it out.

0 Votes 0 ·