RESOLVED : File Watcher fires off 2 events?
Long experienced in programming, web applications but new to .Net. I found an example of a file watcher application that I am trying to modify to use for an application. When a new file comes into a directory, I want to move it somewhere, open/parse and do db operations on it.
This code looks pretty simple and works well but when I add a file to the directory it is watching, I get two "file was created" messages. Any thoughts?
Url I got example from is :http://www.developerfusion.com/show/3636/3/
Long experienced in programming, web applications but new to .Net. I found an example of a file watcher application that I am trying to modify to use for an application. When a new file comes into a directory, I want to move it somewhere, open/parse and do db operations on it.
This code looks pretty simple and works well but when I add a file to the directory it is watching, I get two "file was created" messages. Any thoughts?
VB.NET:
Private Sub btn_startwatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_startwatch.Click
watchfolder = New System.IO.FileSystemWatcher
watchfolder.Path = txt_watchpath.Text
watchfolder.NotifyFilter = IO.NotifyFilters.DirectoryName
watchfolder.NotifyFilter = watchfolder.NotifyFilter Or IO.NotifyFilters.FileName
watchfolder.NotifyFilter = watchfolder.NotifyFilter Or IO.NotifyFilters.Attributes
AddHandler watchfolder.Created, AddressOf logchange
watchfolder.EnableRaisingEvents = True
btn_startwatch.Enabled = False
btn_stop.Enabled = True
End Sub
Private Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
If e.ChangeType = IO.WatcherChangeTypes.Created Then
txt_folderactivity.Text &= "File " & e.FullPath & _
" has been created" & vbCrLf
End If
End Sub
Private Sub txt_watchpath_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_watchpath.TextChanged
End Sub
Private Sub txt_folderactivity_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_folderactivity.TextChanged
End Sub
Private Sub btn_stop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_stop.Click
watchfolder.EnableRaisingEvents = False
btn_startwatch.Enabled = True
btn_stop.Enabled = False
End Sub
Url I got example from is :http://www.developerfusion.com/show/3636/3/
Last edited: