ASP.NET - Microsoft Report viewer

Asked By Ravi Maurya on 26-Apr-11 03:37 PM
how to add print command in microsoft report viewer
Nikhil Mahajan replied to Ravi Maurya on 26-Apr-11 08:38 PM
you can use the print commands on the ReportViewer toolbar to open a Print dialog box, preview the report in print layout, and configure page setup prior to printing.

The ReportViewer Web server control, when used with server reports, provides an ActiveX print control that you can use instead of browser print functionality. In contrast with browser print functionality, the print control allows you to print all of the pages of a paginated report, without the page information that some browsers add to the printout. Depending on browser settings, you might need to download and configure the control.


Configuring the Print Control for Server Reports Using the ReportViewer Web Server Control

The ReportViewer Web server control provides an ActiveX print control for server reports that are processed on a remote SQL Server 2005 Reporting Services report server. This control downloads automatically the first time the Print command on the ReportViewer toolbar is clicked, and is installed on the client computer. If the user does not install the control, or if support for the print control is disabled on the report server, the Print command cannot be used. After the control is installed, users can use the print control to print server reports configured to run in the ReportViewer Web server control.

Depending on browser settings, each user might need to configure the browser to enable an ActiveX control download. To configure Internet Explorer to allow ActiveX control downloads, follow these steps:

  1. In Microsoft Internet Explorer, from the Tools menu, choose Internet Options, and then click the Security tab.

  2. Select the Trusted sites Web content zone, and then click Sites.

  3. Type the report server URL. By default, this is https://<ComputerName>/reportserver if you are using Secure Sockets Layer (SSL).

  4. Click Add, and then click OK.

  5. Click the Custom Level button. Scroll to the ActiveX controls and plug-ins node.

  6. Click Enable for Download signed ActiveX controls, and then click OK.

TSN ... replied to Ravi Maurya on 26-Apr-11 11:51 PM
hi...

Printing a local report without preview....

using System;
using System.IO;
using System.Data;
using System.Text;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
 
public class Demo : IDisposable
{
  private int m_currentPageIndex;
  private IList<Stream> m_streams;
 
  private DataTable LoadSalesData()
  {
    // Create a new DataSet and read sales data file
    //    data.xml into the first DataTable.
    DataSet dataSet = new DataSet();
    dataSet.ReadXml(@"..\..\data.xml");
    return dataSet.Tables[0];
  }
  // Routine to provide to the report renderer, in order to
  //    save an image for each page of the report.
  private Stream CreateStream(string name,
    string fileNameExtension, Encoding encoding,
    string mimeType, bool willSeek)
  {
    Stream stream = new FileStream(@"..\..\" + name +
       "." + fileNameExtension, FileMode.Create);
    m_streams.Add(stream);
    return stream;
  }
  // Export the given report as an EMF (Enhanced Metafile) file.
  private void Export(LocalReport report)
  {
    string deviceInfo =
      "<DeviceInfo>" +
      "  <OutputFormat>EMF</OutputFormat>" +
      "  <PageWidth>8.5in</PageWidth>" +
      "  <PageHeight>11in</PageHeight>" +
      "  <MarginTop>0.25in</MarginTop>" +
      "  <MarginLeft>0.25in</MarginLeft>" +
      "  <MarginRight>0.25in</MarginRight>" +
      "  <MarginBottom>0.25in</MarginBottom>" +
      "</DeviceInfo>";
    Warning[] warnings;
    m_streams = new List<Stream>();
    report.Render("Image", deviceInfo, CreateStream,
       out warnings);
    foreach (Stream stream in m_streams)
      stream.Position = 0;
  }
  // Handler for PrintPageEvents
  private void PrintPage(object sender, PrintPageEventArgs ev)
  {
    Metafile pageImage = new
       Metafile(m_streams[m_currentPageIndex]);
    ev.Graphics.DrawImage(pageImage, ev.PageBounds);
    m_currentPageIndex++;
    ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
  }
 
  private void Print()
  {
    const string printerName =
       "Microsoft Office Document Image Writer";
    if (m_streams == null || m_streams.Count == 0)
      return;
    PrintDocument printDoc = new PrintDocument();
    printDoc.PrinterSettings.PrinterName = printerName;
    if (!printDoc.PrinterSettings.IsValid)
    {
      string msg = String.Format(
         "Can't find printer \"{0}\".", printerName);
      MessageBox.Show(msg, "Print Error");
      return;
    }
    printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
    printDoc.Print();
  }
  // Create a local report for Report.rdlc, load the data,
  //    export the report to an .emf file, and print it.
  private void Run()
  {
    LocalReport report = new LocalReport();
    report.ReportPath = @"..\..\Report.rdlc";
    report.DataSources.Add(
       new ReportDataSource("Sales", LoadSalesData()));
    Export(report);
    m_currentPageIndex = 0;
    Print();
  }
 
  public void Dispose()
  {
    if (m_streams != null)
    {
      foreach (Stream stream in m_streams)
        stream.Close();
      m_streams = null;
    }
  }
 
  public static void Main(string[] args)
  {
    using (Demo demo = new Demo())
    {
      demo.Run();
    }
  }
}
hope this helps you.........
Ravi Maurya replied to Nikhil Mahajan on 27-Apr-11 01:24 AM
thank you sir for instructing me step by step

could you please tell me how to enable the print command for firefox and chrome
Riley K replied to Ravi Maurya on 27-Apr-11 01:41 AM
You have to include script to enable print in firefox, see below link
http://

Ravi Maurya replied to Riley K on 27-Apr-11 01:47 AM
I have put that script in head section but not getting print button

is that necessary to include dll..??
Riley K replied to Ravi Maurya on 27-Apr-11 02:28 AM
Yes you have to include the DLL also
Carol replied to Ravi Maurya on 13-May-11 09:38 AM
The print button prints the window but does not print the reportviewer serverreport.  Any idea what I'm doing wrong?

Thanks