C# .NET - How to know Printer name using C# - Asked By svt gdwl on 19-May-09 12:48 AM

Hi,
when we give print a web page opened on browser, how can we know the details of printer like its name etc., using c#?

RE - Ravenet Rasaiyah replied to svt gdwl on 19-May-09 12:54 AM

Hi

I dont think this is possible directly. You would need the client's permission eventually to print from their system.

Just check here for more information

http://www.4guysfromrolla.com/webtech/030602-1.shtml

thank you
Santhosh N replied to svt gdwl on 19-May-09 01:07 AM

You could use this API in .net to get the printers avaialble..

http://msdn.microsoft.com/en-us/library/zhds6k80.aspx

Also, you could check this which you could get using vbscript APIs in client side..

http://www.eggheadcafe.com/community/aspnet/3/6172/try-something-like-this.aspx

Alice J replied to svt gdwl on 19-May-09 01:15 AM

This code should give you the list of all the printers available for the system.

 

private void button1_Click(object sender, EventArgs e)

        {

            try

            {

                foreach (String strPrinter in System.Drawing.Printing.PrinterSettings.InstalledPrinters)

                {

                    listBox1.Items.Add(strPrinter);

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

        }

Alice J replied to svt gdwl on 19-May-09 01:19 AM

This is the code to get the printer status.

using System;
using System.Management;


enum PrinterStatus {
Other = 1,
Unknown,
Idle,
Printing,
Warmup,
Stopped,
printing,
Offline
}

public class Wmis {
public static void Main() {
PrinterStatus stat;
if ((stat = GetPrinterStat("\\\\server\\printername")) != 0) // UNC or a
local name
{
Console.WriteLine(stat);
}
else
Console.WriteLine("Failed to get status");
}
static PrinterStatus GetPrinterStat(string printerDevice)
{
PrinterStatus ret = 0;
string path = "win32_printer.DeviceId='" + printerDevice + "'";
using (ManagementObject printer = new ManagementObject(path))
{
printer.Get();
PropertyDataCollection printerProperties = printer.Properties;
PrinterStatus st =
(PrinterStatus)Convert.ToInt32(printer.Properties["PrinterStatus"].Value);
ret = st;
}
return ret;
}
}

want to know the name of Printer which has been selected before giving the printe
Asked By svt gdwl on 19-May-09 01:25 AM
Hi I want the same thing almost, If there are 3types of printers installed,
I want to know the name of Printer which has been selected before giving the printer