Monitoring a folder for new files in .net can easily be watched using the FileSystemWatcher in System.IO. You give it a path (ie: C:\toprint) and it will raise an event when a file is created (you can also watch for deleted, renamed and updated files).
Edit: I have new / full code here on GitHub.
I’ve had the need on several occasions to print new files as they are created, so the combination of the FileSystemWatcher and using a process to call the file and print work well together. Below the code to print to the default printer (works great for .pdf files):
Process PrintProcess = new Process();
PrintProcess.StartInfo.CreateNoWindow = false;
PrintProcess.StartInfo.Verb = "print";
PrintProcess.StartInfo.FileName = e.FullPath;
Dim PrintProcess As New Process
PrintProcess.StartInfo.CreateNoWindow = False
PrintProcess.StartInfo.Verb = "print"
PrintProcess.StartInfo.FileName = e.FullPath
The file watcher uses this syntax:
FileSystemWatcher fsWatcher = new FileSystemWatcher(txtDirToWatch.Text);
fsWatcher.Created += OnChanged;
var withFSW = fsWatcher;
withFSW.EnableRaisingEvents = true;
withFSW.IncludeSubdirectories = false;
withFSW.Filter = "*.pdf";
Dim fsWatcher As New FileSystemWatcher(txtDirToWatch.Text)
AddHandler fsWatcher.Created, AddressOf OnChanged
.EnableRaisingEvents = True
.IncludeSubdirectories = False
.Filter = "*.pdf"
And the OnChanged Event: c#:
public void OnChanged(object source, FileSystemEventArgs e)
//Do something with e.FullPath, etc.
Public Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
'Do something with e.FullPath, etc.
*I haven’t used this method to print many different formats or tons of files at once, but give it a try!
If you’d like a fully working solution (vb or c#) drop me a line at chris.bitting(at)gmail(dot)com and I’d be glad to send my project and code.