Question : add a new print job and getting its ID

Hey all

CurrentlyI am using ASP.net to print off documents to specific printers in my network, and chaning the print owner using the ID

however i would like to develop an application that prints a a file in my server then get its ID, the add job function does that but It doesnt pick the ID for you
I was thinking I could retreive the Job ID from the time stamp of a job
But according to my manager, some sites have issues with the printjobs being printed at the same second

so i wouldnt know whichprintjob ID belongs to which owner

then i thought using miliseconds but unfortunatly when i use Datetime.now it gets a 100ms margin error
so is there a way of asking windows,please print this document and give me the ID which you gave it?

Answer : add a new print job and getting its ID

u can use the following functions to get printers jobs and their properties
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
static void Main()
        {
            StringCollection col = GetPrintersCollection();
            foreach (var printer in col)
            {
                Console.WriteLine(printer);
                foreach (var job in GetPrintJobsCollection(printer))
                {
                    Console.WriteLine(job);
                }
            }
            Console.Read();
        }
 
        public static StringCollection GetPrintersCollection()
        {
            StringCollection printerNameCollection = new StringCollection();
            string searchQuery = "SELECT * FROM Win32_Printer";
            ManagementObjectSearcher searchPrinters =
                  new ManagementObjectSearcher(searchQuery);
            ManagementObjectCollection printerCollection = searchPrinters.Get();
            foreach (ManagementObject printer in printerCollection)
            {
                printerNameCollection.Add(printer.Properties["Name"].Value.ToString());
            }
            return printerNameCollection;
        }
 
        public static StringCollection GetPrintJobsCollection(string printerName)
        {
            StringCollection printJobCollection = new StringCollection();
            string searchQuery = "SELECT * FROM Win32_PrintJob";
 
            /*searchQuery can also be mentioned with where Attribute,
                but this is not working in Windows 2000 / ME / 98 machines 
                and throws Invalid query error*/
            ManagementObjectSearcher searchPrintJobs =
                      new ManagementObjectSearcher(searchQuery);
            ManagementObjectCollection prntJobCollection = searchPrintJobs.Get();
            foreach (ManagementObject prntJob in prntJobCollection)
            {
                System.String jobName = prntJob.Properties["Name"].Value.ToString();
 
                //Job name would be of the format [Printer name], [Job ID]
                char[] splitArr = new char[1];
                splitArr[0] = Convert.ToChar(",");
                string prnterName = jobName.Split(splitArr)[0];
                string documentName = prntJob.Properties["Document"].Value.ToString();
                if (String.Compare(prnterName, printerName, true) == 0)
                {
                    printJobCollection.Add(documentName);
                }
            }
            return printJobCollection;
        }
Random Solutions  
 
programming4us programming4us