[Solved] Print ASP.Net ReportViewer Error: No printers are installed in IIS

on Apr 12, 2021 07:52 PM


I have been tried Print ReportViewer without Print Preview using C# and VB.Net in ASP.Net

  1. Internet explorer -- working
  2. Google Chrome -- not working
  3. Microsoft Edge -- working
  4. Print not proposedly scaled

It worked in well on the localhost.

But not working in remote host IIS server.

the error log as follows


The process cannot access the file because it is being used by another process

IE and Chrome

No printers are installed

Please advise fixed above 2 and 4

Thank You


Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Apr 14, 2021 03:16 AM
on Jan 10, 2022 10:03 AM

Hi samsmuthu,

Refer the updated code.

Make sure there is a default printer configured for the server.

Make sure the identity under which the web application is running has permission to access the printer.


I have made use of the following table Customers with the schema as follows.

I have already inserted few records in the table.

You can download the database table SQL by clicking the download link below.

Download SQL file


<asp:ScriptManager runat="server" />
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="300" Height="300"></rsweb:ReportViewer>
<br />
<asp:Button Text="Print" runat="server" OnClick="Print" />



using System.Configuration;
using System.Data.SqlClient;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.IO;
using System.Text;
using Microsoft.Reporting.WebForms;


Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Drawing.Imaging
Imports System.Drawing.Printing
Imports System.IO
Imports System.Text
Imports Microsoft.Reporting.WebForms



private int pageIndex = 0;
private IList<Stream> streams;
protected void Page_Load(object sender, EventArgs e)
    if (!IsPostBack)
        ReportViewer1.ProcessingMode = ProcessingMode.Local;
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
        Customers dsCustomers = GetData("select top 5 * from customers");
        ReportDataSource datasource = new ReportDataSource("Customers", dsCustomers.Tables[0]);

protected void Print(object sender, EventArgs e)
    pageIndex = 0;

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>" +
    Warning[] warnings;
    streams = new List<Stream>();
    report.Render("Image", deviceInfo, CreateStream, out warnings);
    foreach (Stream stream in streams)
        stream.Position = 0;

private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
    Stream stream = new FileStream(Server.MapPath("~/Files/") + name + DateTime.Now.ToString("ddMMyyyyHHMMss") + "." + fileNameExtension, FileMode.Create);
    return stream;

private void Print()
    if (streams == null || streams.Count == 0)
    PrintDocument printDoc = new PrintDocument();
    printDoc.PrintPage += new PrintPageEventHandler(PrintPage);

private void PrintPage(object sender, PrintPageEventArgs ev)
    Metafile pageImage = new Metafile(streams[pageIndex]);
    ev.Graphics.DrawImage(pageImage, ev.PageBounds);
    ev.HasMorePages = (pageIndex < streams.Count);

private Customers GetData(string query)
    string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    SqlCommand cmd = new SqlCommand(query);
    using (SqlConnection con = new SqlConnection(conString))
        using (SqlDataAdapter sda = new SqlDataAdapter())
            cmd.Connection = con;
            sda.SelectCommand = cmd;
            using (Customers dsCustomers = new Customers())
                sda.Fill(dsCustomers, "DataTable1");
                return dsCustomers;


Private pageIndex As Integer = 0
Private streams As IList(Of Stream)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not IsPostBack Then
        ReportViewer1.ProcessingMode = ProcessingMode.Local
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc")
        Dim dsCustomers As Customers = GetData("select top 5 * from customers")
        Dim datasource As ReportDataSource = New ReportDataSource("Customers", dsCustomers.Tables(0))
    End If
End Sub

Protected Sub Print(ByVal sender As Object, ByVal e As EventArgs)
    pageIndex = 0
End Sub

Private Sub Export(ByVal report As LocalReport)
    Dim deviceInfo As String = "<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>" &
    Dim warnings As Warning()
    streams = New List(Of Stream)()
    report.Render("Image", deviceInfo, AddressOf CreateStream, warnings)
    For Each stream As Stream In streams
        stream.Position = 0
End Sub

Private Function CreateStream(ByVal name As String, ByVal fileNameExtension As String, ByVal encoding As Encoding, ByVal mimeType As String, ByVal willSeek As Boolean) As Stream
    Dim stream As Stream = New FileStream(Server.MapPath("~/Files/") & name & DateTime.Now.ToString("ddMMyyyyHHMMss") & "." & fileNameExtension, FileMode.Create)
    Return stream
End Function

Private Sub Print()
    If streams Is Nothing OrElse streams.Count = 0 Then
    End If

    Dim printDoc As PrintDocument = New PrintDocument()
    AddHandler printDoc.PrintPage, AddressOf PrintPage
End Sub

Private Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
    Dim pageImage As Metafile = New Metafile(streams(pageIndex))
    ev.Graphics.DrawImage(pageImage, ev.PageBounds)
    pageIndex += 1
    ev.HasMorePages = (pageIndex < streams.Count)
End Sub

Private Function GetData(ByVal query As String) As Customers
    Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
    Dim cmd As SqlCommand = New SqlCommand(query)
    Using con As SqlConnection = New SqlConnection(conString)
        Using sda As SqlDataAdapter = New SqlDataAdapter()
            cmd.Connection = con
            sda.SelectCommand = cmd
            Using dsCustomers As Customers = New Customers()
                sda.Fill(dsCustomers, "DataTable1")
                Return dsCustomers
            End Using
        End Using
    End Using
End Function