.net 我怎么知道SPL文件是完全写在里面的?
我想获取打印机当前的打印作业信息,因此我转到文件夹.net 我怎么知道SPL文件是完全写在里面的?,.net,printing,printqueuewatch,.net,Printing,Printqueuewatch,我想获取打印机当前的打印作业信息,因此我转到文件夹C:\Windows\System32\spool\PRINTERS,并使用以下代码获取spool文件信息 Public WithEvents _universalPrinterMonitor As PrinterQueueWatch.PrinterMonitorComponent Private Sub UniversalPrinterMonitor_JobAdded(ByVal sender As Object, ByVal args As
C:\Windows\System32\spool\PRINTERS
,并使用以下代码获取spool文件信息
Public WithEvents _universalPrinterMonitor As PrinterQueueWatch.PrinterMonitorComponent
Private Sub UniversalPrinterMonitor_JobAdded(ByVal sender As Object, ByVal args As PrinterQueueWatch.PrintJobEventArgs) Handles _universalPrinterMonitor.JobAdded
Try
Dim fs As IO.FileStream
If File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\" & args.PrintJob.JobId.ToString("D5") & ".SPL") Then
fs = New IO.FileStream(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\" & args.PrintJob.JobId.ToString("D5") & ".SPL", _
IO.FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\" & args.PrintJob.JobId.ToString("D5") & ".SPL")
ElseIf File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\FP" & args.PrintJob.JobId.ToString("D5") & ".SPL") Then
fs = New IO.FileStream(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\FP" & args.PrintJob.JobId.ToString("D5") & ".SPL", _
IO.FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\FP" & args.PrintJob.JobId.ToString("D5") & ".SPL")
Else
args.PrintJob.Delete()
MessageBox.Show("There was an error occured while executing your print job, please contact your system administrator for assistance.", _
"Spool File Not Found!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Throw New Exception("Spool File Not Found. System Path: " & Environment.GetFolderPath(Environment.SpecialFolder.System) & ". Spool File Id: " & _
args.PrintJob.JobId.ToString("D5") & ".SPL")
End If
Using fs
'Thread.Sleep(1000)
Dim sr As New IO.StreamReader(fs)
Dim buffer As String
Dim isEOF As Boolean = False
Dim isColor As Boolean = False
While Not isEOF
buffer = sr.ReadLine
If buffer Is Nothing Then
isEOF = True
Exit While
End If
If buffer.Contains("RENDERMODE=COLOR") Then
isColor = True
isEOF = True
Exit While
End If
End While
但是,有时我可以正确获取打印作业颜色类型,有时则不能,因为buffer=sr.ReadLine
返回了NULL对象,并且我假设我的程序没有完全读取spool文件
此外,我尝试了PrintQueueWatch
args.PrintJob.Color
,但无论我将文档颜色类型更改为“B&W”或“Color”,它都会返回“true”
在读取spool文件或使用PrintQueueWatch时,还有什么需要注意的吗?提前谢谢~ 您需要监视JobWrite事件(而不是JobAdded),并且只有在触发该事件并且PrintJob.Spooling=false时才开始读取假脱机文件