How to implement your FileSystemWatcher
Step 1
Once you have created your FileSystemWatcher, you need to set certain parameters for it.
Step 2
We will do this in the Form_Load event. What we are trying to do is to create a FileSystemWatcher event that will detect creation of file with the extension TXT to it’s directory only – not inclusive of subdirectories. This is all configuring with the codes below.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FileSystemWatcher1.Path = "c:\im"
FileSystemWatcher1.Filter = "*.txt"
FileSystemWatcher1.IncludeSubdirectories = False
FileSystemWatcher1.EnableRaisingEvents = True
End Sub
Step 3
Then to implement our FILE CREATION event,
Step 4
Go to your FileSytemWatcher1 object and then select it’s events under Declaration in the Created
Step 5
Under this control, use the MsgBox to notify user that a TXT file has been created in your folder called IM.
Private Sub FileSystemWatcher1_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created
MsgBox("A newly created TXT file is detected")
End Sub
Edited By:Melanie Michael Jominin
© 2001 ISC/Inner Esteem
All rights reserved. All other product names and trademarks are registered properties of their respective owners.
301001