Detect Newly Created Files (of Specific *.??? 3 letter extention) in VS 2013 C#

Posted on 2013-12-21
Medium Priority
Last Modified: 2013-12-21

I need example code in C# that will detect PDF files that are uploaded via Windows file share. (For me, this will be used to detect Acrobat PDF files from a multi-purpose scanner to integrate into a larger management system.)

Please: This should be simple, concise & bug-free Visual Studio 2013 C# code for Windows.

Thank you in advance! Happy Coding! :)
Question by:DumbBoxRox
LVL 37

Accepted Solution

TommySzalapski earned 2000 total points
ID: 39733624
Please: This should be simple, concise & bug-free Visual Studio 2013 C# code for Windows.
Note that Experts Exchange is not a freelance coder website. If you are looking for someone to write a full solution, you would have better success probably at some place like freelancer.com. We will certainly do our best to help, though.

What you are wanting to do is quite easy. The FileSystemWatcher class was designed to do exactly that. Try something like this
using System.IO;
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "C:\directoryToSearch"; // edit this to the path you want to search
watcher.Filter = "*.pdf"; // find pdfs
watcher.IncludeSubdirectories = true; // also watch subdirectories
watcher.Created += new FileSystemEventHandler(NewFileHandler); // set up the handler
watcher.EnableRaisingEvents = true; //start listening

Open in new window

Then the event handler would look like this

private static void NewFileHandler(object source, FileSystemEventArgs e)
    // Do your handling here
   Console.WriteLine("New file seen at: " +  e.FullPath);

Open in new window


Author Closing Comment

ID: 39733771

Yes. I was looking just for a snippet, not a full solution. I understand your comment though because of abuse. I have not used the Microsoft .NET API for quite some time, and wanted a professional answer (and you gave me one), so I will reward you with your full amount of points.

Thank you.

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Make the most of your online learning experience.
This article describes and provides a custom-made tool I wrote to give businesses a means of identifying commercial music content, without having to expend too much effort. Business recordings are easily identified from possibly illegal music files …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Screencast - Getting to Know the Pipeline

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question