How to get the printer name installed on client pc by using C# in ASP.

How to get printer list on client and their printer status

Page 1 of 1

1 Replies - 9526 Views - Last Post: 10 November 2009 - 10:17 PM Rate Topic: -----

#1 pawan.net  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-July 09

How to get the printer name installed on client pc by using C# in ASP.

Post icon  Posted 10 November 2009 - 10:14 PM

I have to write the code by which I can find the printer list installed on the clients and their status. The application will be in C#, ASP.net. i.e. Client Server application


It is my print.cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing.Printing;
using System.Drawing;
using System.Printing;


/// <summary>
/// Summary description for PrintP
/// </summary>
public class PrintP
{
	public void RunSample()
	{
		
		PrintDocument pd = new PrintDocument();
		pd.PrintPage += new PrintPageEventHandler(this.PrintPageEvent);
		pd.Print();
	}

	private void PrintPageEvent(object sender, PrintPageEventArgs ev)
	{
		string strHello = "Hello Printer!";
		Font oFont = new Font("Arial", 10);
		Rectangle marginRect = ev.MarginBounds;

		ev.Graphics.DrawRectangle(new Pen(System.Drawing.Color.Black), marginRect);
		ev.Graphics.DrawString(strHello, oFont, new SolidBrush(System.Drawing.Color.Blue),
		  (ev.PageBounds.Right / 2), ev.PageBounds.Bottom / 2);
	}
}




it is my aspx file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing.Printing;
using System.Printing;



public partial class _Default : System.Web.UI.Page 
{
	PrintSystemJobInfo pinf;
   
   
 
	protected void Page_Load(object sender, EventArgs e)
	{
			  PrinterSettings ps = new PrinterSettings();

		try
		{
			PrintDocument pd1 = new PrintDocument();
			//pd1.PrinterSettings.PrinterName = "HP LaserJet 5P";
			// ps.PrinterName = "HP Laserjet2100";
			 

			Response.Write("The printer Name is   : " + pd1.PrinterSettings.PrinterName );
			PrintP oSample = new PrintP();
			oSample.RunSample();
		}
		catch (Exception ex)
		{
			Response.Write("I am your exception"+ex);
		}
	}
}  




now I have to check the priner name and status of the printer installed on client

I have got this code on net to get the status by using printsystemjobinfo class. But how i will use this in my above aspx or cs file, I am not able to create the object due to the protection label.


// Check for possible trouble states of a print job using the flags of the JobStatus property
internal static void SpotTroubleUsingJobAttributes(PrintSystemJobInfo theJob)
{
	if ((theJob.JobStatus & PrintJobStatus.Blocked) == PrintJobStatus.Blocked)
	{
		Console.WriteLine("The job is blocked.");
	}
	if (((theJob.JobStatus & PrintJobStatus.Completed) == PrintJobStatus.Completed)
		|| 
		((theJob.JobStatus & PrintJobStatus.Printed) == PrintJobStatus.Printed))
	{
		Console.WriteLine("The job has finished. Have user recheck all output bins and be sure the correct printer is being checked.");
	}
	if (((theJob.JobStatus & PrintJobStatus.Deleted) == PrintJobStatus.Deleted)
		|| 
		((theJob.JobStatus & PrintJobStatus.Deleting) == PrintJobStatus.Deleting))
	{
		Console.WriteLine("The user or someone with administration rights to the queue has deleted the job. It must be resubmitted.");
	}
	if ((theJob.JobStatus & PrintJobStatus.Error) == PrintJobStatus.Error)
	{
		Console.WriteLine("The job has errored.");
	}
	if ((theJob.JobStatus & PrintJobStatus.Offline) == PrintJobStatus.Offline)
	{
		Console.WriteLine("The printer is offline. Have user put it online with printer front panel.");
	}
	if ((theJob.JobStatus & PrintJobStatus.PaperOut) == PrintJobStatus.PaperOut)
	{
		Console.WriteLine("The printer is out of paper of the size required by the job. Have user add paper.");
	}

	if (((theJob.JobStatus & PrintJobStatus.Paused) == PrintJobStatus.Paused)
		|| 
		((theJob.HostingPrintQueue.QueueStatus & PrintQueueStatus.Paused) == PrintQueueStatus.Paused))
	{
		HandlePausedJob(theJob);
		//HandlePausedJob is defined in the complete example.
	}

	if ((theJob.JobStatus & PrintJobStatus.Printing) == PrintJobStatus.Printing)
	{
		Console.WriteLine("The job is printing now.");
	}
	if ((theJob.JobStatus & PrintJobStatus.Spooling) == PrintJobStatus.Spooling)
	{
		Console.WriteLine("The job is spooling now.");
	}
	if ((theJob.JobStatus & PrintJobStatus.UserIntervention) == PrintJobStatus.UserIntervention)
	{
		Console.WriteLine("The printer needs human intervention.");
	}

}//end SpotTroubleUsingJobAttributes





This code I also got on net to get the job code or id or list

But How can I use this in my above application.

Please suggest me , I am begineer and I have to use this any how.

If any other code by using java script or activex also suggest me.

Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

This post has been edited by pawan.net: 11 November 2009 - 01:36 AM


Is This A Good Question/Topic? 0
  • +

Replies To: How to get the printer name installed on client pc by using C# in ASP.

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How to get the printer name installed on client pc by using C# in ASP.

Posted 10 November 2009 - 10:17 PM

Moved to ASP.NET :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1