title: Unable to access the printer when hosting to iis
body: <p>I am using rdlc report in MVC,Printing operation works perfectly when running in visual studio, but when published to iis which is set up in the same machine,printing operation is not taking place.But when I return the report as pdf the report it is there,and I can print the file using javascript.But I actually need not want to display the report but want to print from server..Thanks For help in advance</p>
  
  <pre><code>  public ActionResult GenerateOrder()
      {
  
  
          try
          {
  
              LocalReport report = new LocalReport();
              report.ReportPath = (Server.MapPath("~/Reports/Report1.rdlc"));
              Export(report);
              Print();
          }
          catch (Exception Ex)
          {
  
          }
  
          return View();
      }
  
      private Stream CreateStream(string name,
      string fileNameExtension, Encoding encoding,
      string mimeType, bool willSeek)
      {
          Stream stream = new MemoryStream();
          m_streams.Add(stream);
          return stream;
      }
       private void Export(LocalReport report)
      {
          string deviceInfo =
            @"&lt;DeviceInfo&gt;
              &lt;OutputFormat&gt;EMF&lt;/OutputFormat&gt;
              &lt;PageWidth&gt;8.5in&lt;/PageWidth&gt;
              &lt;PageHeight&gt;11in&lt;/PageHeight&gt;
              &lt;MarginTop&gt;0.25in&lt;/MarginTop&gt;
              &lt;MarginLeft&gt;0.25in&lt;/MarginLeft&gt;
              &lt;MarginRight&gt;0.25in&lt;/MarginRight&gt;
              &lt;MarginBottom&gt;0.25in&lt;/MarginBottom&gt;
          &lt;/DeviceInfo&gt;";
          Warning[] warnings;
          m_streams = new List&lt;Stream&gt;();
          report.Render("Image", deviceInfo, CreateStream,
             out warnings);
          foreach (Stream stream in m_streams)
              stream.Position = 0;
      }
      private int m_currentPageIndex;
      private IList&lt;Stream&gt; m_streams;
  
      private void PrintPage(object sender, PrintPageEventArgs ev)
      {
          try
          {
              Metafile pageImage = new
                          Metafile(m_streams[m_currentPageIndex]);
  
              // Adjust rectangular area with printer margins.
              Rectangle adjustedRect = new Rectangle(
                  ev.PageBounds.Left - (int)ev.PageSettings.HardMarginX,
                  ev.PageBounds.Top - (int)ev.PageSettings.HardMarginY,
                  ev.PageBounds.Width,
                  ev.PageBounds.Height);
  
              // Draw a white background for the report
              ev.Graphics.FillRectangle(Brushes.White, adjustedRect);
  
              // Draw the report content
              ev.Graphics.DrawImage(pageImage, adjustedRect);
  
              // Prepare for the next page. Make sure we haven't hit the end.
              m_currentPageIndex++;
              ev.HasMorePages = (m_currentPageIndex &lt; m_streams.Count);
          }
          catch (Exception ex)
          {
  
          }
  
      }
     private void Print()
      {
          if (m_streams == null || m_streams.Count == 0)
              throw new Exception("Error: no stream to print.");
          PrintDocument printDoc = new PrintDocument();
          if (!printDoc.PrinterSettings.IsValid)
          {
              throw new Exception("Error: cannot find the default printer.");
          }
          else
          {
  
              PrinterSettings pset = new PrinterSettings();
              printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
              m_currentPageIndex = 0;
              printDoc.PrinterSettings.PrinterName = pset.PrinterName;
              printDoc.Print();
          }
      }
  </code></pre>