
- #Moniter newly added files using filewatcher how to#
- #Moniter newly added files using filewatcher code#
(I left this file named as Installer1.cs.) In order to accomplish this, we must first add an InstallerClass file to our project ("Project->Add New Item."): The last item at hand for completion of this project is to create the windows installer class to allow the project to be compiled as a Windows service. This will be the actual name that shows up in the "Services" window in the Control Panel, once the service is installed. Lastly, go into the properties for Service1.cs (in design), and change the ServiceName property to something meaningful. System.IO.File.Copy(e.FullPath, " C:\\temp\\archive\\" + e.Name) For example, if you want to copy a file that is dropped into your defined "watch" directory, you would use something like this within the FSWatcherTest_Created() event:
#Moniter newly added files using filewatcher code#
code here for newly renamed file or directoryĪdd whatever code is necessary within each event, and it will get executed when the event is fired. / private void FSWatcherTest_Renamed( object sender, / /// Event occurs when the a File or Directory is renamed code here for newly deleted file or directory / private void FSWatcherTest_Deleted( object sender, / /// Event occurs when the a File or Directory is deleted code here for newly created file or directory / private void FSWatcherTest_Created( object sender, / /// Event occurs when the a File or Directory is created code here for newly changed file or directory / private void FSWatcherTest_Changed( object sender, */ /// /// Event occurs when the contents of a File or Directory are changed Within the configuration which we've just added, we will need to add an " appSettings" section, where we'll define our directory path: We will use this to define a directory (path) to "watch": Now, add a new Application Configuration File to the project. Add a reference to " System.Configuration" by right-clicking on the project, then "Add Reference.": Next, an appropriate reference must be added to the project as we will be using an application configuration file. I named this sample solution TestCSWinWatcherService and optionally, chose to create a directory for the solution file. Using the codeįirst, open Visual Studio.NET and create a new Windows Service project for C#: You must have a machine running Microsoft.
#Moniter newly added files using filewatcher how to#
This article will briefly explain how to set up a simple "File Watcher/ Directory Watcher" application to run as a Windows Service using Visual Studio 2005.
