1

i want to print to the client side printer in the same network in my asp.net application hosted in IIS. i used the following print code. but it can only print to the printers installed to the server. in the following code you can see i have added the printer path of the printer installed in the server "\\Server\LaserPrinter3501", but if i give the path of another shared printer in the same network, it will not print.

protected void btnprint_Click(object sender, EventArgs e)
{
    prntKOT.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(3, 3, 3, 3);
    PaperSize pSize = new PaperSize();
    pSize.Width = 315;
    pSize.Height = 380;
    prntKOT.DefaultPageSettings.PaperSize = pSize;
    prntKOT.PrintPage += new PrintPageEventHandler(prntKOT_PrintPage);
    prntKOT.PrinterSettings.PrinterName = "\\Server\LaserPrinter3501";
    prntKOT.Print(); 
}

private void prntKOT_PrintPage(object sender, PrintPageEventArgs e)
    {
            Graphics g = e.Graphics;
            g.PageUnit = GraphicsUnit.Millimeter;
            float width = prntKOT.DefaultPageSettings.PaperSize.Width;
            e.HasMorePages = false;
            Font printFont = new Font("Arial", 8);
            Pen p = new Pen(Brushes.Black, 0);
            p.Color = System.Drawing.Color.Black;
            p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
            g.DrawString("Hello World !", printFont, Brushes.Black, 10, 10);
     
    }

Please give a solution to do client side printing.

anandd360
  • 298
  • 3
  • 14
  • Generate a PDF and ask the user to print from browser. ASP.NET on IIS won't be able to access client side printers due to isolation. – Lex Li Feb 25 '21 at 03:57
  • @LexLi in case browser is sending the command to print your point is valid. But when server IIS has proper access I don't thing that should be a challenge. The only thing is to confirm that weather the IIS user has access of the printer or not. – शेखर Feb 25 '21 at 04:56
  • [Similar question on SO](https://stackoverflow.com/questions/42827027/unable-to-access-the-printer-when-hosting-to-iis) – शेखर Feb 25 '21 at 05:00
  • For information about "Configure Internet printing in IIS", you can refer to this link: https://learn.microsoft.com/en-us/troubleshoot/windows-server/printing/manage-connect-printers-use-web-browser – Ding Peng Feb 25 '21 at 07:33

0 Answers0