Friday, 6 January 2017

Retrieve a List of Installed Printers on the Network Using C# in asp.net


Retrieve a List of Installed Printers on the Network

Description:

In this example we explain that how to display list of printers in client computer in asp.net using C#.or how to find installed printers on client machine in asp.net.retrieve a list of installed printers on network using C#.

Suppose you have requirements likes to display list of printers on the network so below is the code to display it.


Aspx Page:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="Master_LabelPrint"  MasterPageFile="~/TemplatePage.master" Codebehind="LabelPrint.aspx.cs" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td class="content">
                <b>List of installed Printers</b>
                <span id="spn" runat="server">
               
                </span>
            </td>
         </tr>
 </table>    
</asp:Content>

Aspx.CS Page:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Drawing.Printing;
using System.Collections.Generic;

public partial class Master_LabelPrint : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string[] myPrinters = ListPrinters();

        string printHTML = "<ul>";
        for(int p=0; p<myPrinters.Length; p++)
            printHTML = printHTML + "<li>" + myPrinters[p].ToString() + "</li>";
       
        printHTML = printHTML + "</ul>";
        spn.InnerHtml = printHTML;
    }


    public static string[] ListPrinters()
    {
        List<string> lst = new List<string>();
        PrintingPermission PrintPermissions = new PrintingPermission(System.Security.Permissions.PermissionState.Unrestricted);
        PrintPermissions.Level = PrintingPermissionLevel.AllPrinting;
       
        foreach (string printer in PrinterSettings.InstalledPrinters)
        {
            lst.Add(printer);
        }
        lst.Sort();
        return lst.ToArray();
    }

}



1 comments:

  1. ya it is really very much nice and unique information, now i will try those things, really it is a great stuff.

    Digital Marketing Company in Chennai

    ReplyDelete