Share via


File System Watcher Activity Sample

Download sample

This sample shows how to create an activity that can be used to listen for file system events. It illustrates the use of queues in developing an activity that listen for file system events, such as creating a file in a specific folder.

The sample includes a custom service that enables the FileWatcher activity to register interest in a specific kind of file system event. When such an event occurs, the service delivers the event to the activity.

The FileWatcher activity is written so that it functions on its own as well as in an EventDrivenActivity parent activity. This enables the FileWatcher activity to be used, for example, in a ListenActivity activity. This is illustrated in the example workflow that is provided with this sample.

The FileWatcher activity can be configured to have a Path, Filter, NotifyFilter, and a bool value that indicates whether subdirectories of the given Path should be considered. These properties constitute a "subscription" for a specific kind of file system event.

To build the sample

  1. Download the sample by clicking Download Sample.

    This extracts the sample project to your local hard disk.

  2. Click Start, point to Programs, point to Microsoft Windows SDK, and then click CMD Shell.

  3. Go to the source directory of the sample.

  4. At the command prompt, type MSBUILD <Solution file name>.

To run the sample

  1. Create the folders C:\temp and C:\temp2 if they do not already exist.

  2. In the SDK Command Prompt window, run the .exe file in the FileWatcherTestHost\bin\debug folder (or the FileWatcherTestHost\bin folder for the VB version of the sample), which is located below the main folder for the sample.

  3. Drag a file into your C:\temp directory.

    This causes an event to be delivered to the first FileWatcher activity in the workflow.

  4. Drag a file into your C:\temp2 directory.

    This causes an event to be delivered to the second FileWatcher activity in the workflow. The ListenActivity activity has a branch that contains a delay of 20 seconds. If the file is not dropped into the C:\temp2 folder within that time span, the workflow continues to the next step.

  5. Drag a file into your C:\temp directory.

    This causes an event to be delivered to the third FileWatcher activity in the workflow.

See Also

Reference

Activity
DependencyProperty

Other Resources

Creating a Custom Activity
Custom Activities Samples
Synchronized Sample

© 2007 Microsoft Corporation. All rights reserved.