You must Sign In to post a response.
  • Category: Webservices

    How to create a web api for detect all printer of client side in asp.net c#

    Hi All,

    Please tell me , how to create a web api for detect all client side printer using window service in web application.

    please provide solution as possible with code or examples, this is use in hospitality project.

    Thanks & Regards,
    Atul Sharma
  • #758994
    Hello Atul,

    A Web application does not have access to client systems, for a good reason. Imagine for a second that it was possible. Would any reasonable user like that some unknown site could discover printers or other equipment? This even sounds scary.

    You can use javascript function window.Print()
    This will list you client machine printers and print your page.
    Below is code that you can try yourself.

    <html>
    <head>
    <script>
    function printpage()
    {
    window.print()
    }
    </script>
    </head>
    <body>

    <input type="button" value="Print this page" onclick="printpage()">

    </body>
    </html>

    Hope this will help you.
    Mark the answer if it helped you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "If you can dream it, you can do it."

  • #758995
    Hi

    function printClient()
    {
    window.print();// prints the current page.
    }
    <body>
    <input type="button" value="Clientpage"
    onclick="printClient()">
    </body>

    Invoking using JavaScript you can call function with in button click.

    Refer below link I found it may be useful to you.

    www.strathweb.com/2012/10/remote-printing-with-asp-net-web-api-in-windows-service/

    Regards

    Sridhar.
    DNS Member.
    "Hope for the best.. prepare for the worst.."

    Sridhar Thota.
    Editor: DNS Forum.

  • #759012
    You can use following code in windows service and then call it using webapi
    see below snippet
    private void PrinterList()
    {
    // POPULATE THE COMBO BOX.
    foreach (string sPrinters in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
    {
    cmbPrinterList.Items.Add(sPrinters);
    }

    // POPULATE THE LIST BOX.
    foreach (string sPrinters in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
    {
    lstBoxPrinters.Items.Add(sPrinters);
    }
    }
    to create a webapi see below link
    http://www.codeproject.com/Articles/821439/Getting-started-with-ASP-Net-Web-API-using-CodeF

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #759035
    hi Athul,

    Try this code
    <asp:Button ID="printButton" runat="server" Text="Print" OnClientClick="javascript:window.print();" />

    Hope this will help you

    Regards
    Aswini Aluri


  • Sign In to post your comments