Question

I am working on C#.Net Windows Service Application which will send a pdf file to a printer. Pdf files are received from a third party fax service. As soon as fax drops the pdf files, we need to take a print out.

How to achieve by tracking the recent pdf file and sending them to the printer.

Was it helpful?

Solution

Use FileSystemWatcher to monitor the folder.

public void Main()
{
    FileSystemWatcher watcher = new FileSystemWatcher();
    watcher.Path = @"C:\MyPath";
    watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;    
    watcher.Filter = "*.pdf";

    watcher.Created += new FileSystemEventHandler(OnCreated);
}

private static void OnCreated(object source, FileSystemEventArgs e)
{
    //Do something
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top