Click here to Skip to main content
15,949,686 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Hide a listView column Pin
bony_baba10-May-06 1:19
bony_baba10-May-06 1:19 
GeneralRe: Hide a listView column Pin
mounirbraham10-May-06 3:43
mounirbraham10-May-06 3:43 
GeneralRe: Hide a listView column Pin
jcrussell10-May-06 18:45
jcrussell10-May-06 18:45 
QuestionWHERE IS the ListSubItems Icon property ?? Pin
mounirbraham9-May-06 13:52
mounirbraham9-May-06 13:52 
QuestionControlling FileSystemWatcher Pin
Wrongway43219-May-06 10:44
Wrongway43219-May-06 10:44 
AnswerRe: Controlling FileSystemWatcher Pin
DSAlbin21-May-06 7:41
DSAlbin21-May-06 7:41 
GeneralRe: Controlling FileSystemWatcher Pin
Wrongway432123-May-06 12:17
Wrongway432123-May-06 12:17 
GeneralRe: Controlling FileSystemWatcher Pin
DSAlbin23-May-06 13:17
DSAlbin23-May-06 13:17 
GeneralRe: Controlling FileSystemWatcher Pin
Wrongway432124-May-06 10:55
Wrongway432124-May-06 10:55 
Smile | :) Dave,

Thanks for getting back with me. Smile | :) Much appreciated.

Anyway. I must of read an article similar to Jayesh Jain on another interent site before because I had been also playing with simialar example.

Anyway, Jain code works the sameway with the "Change Events" you are correct about limiting the number of "Notifyfilters" to use. I disagree on how Jain uses the following example set for the filter.

wf.NotifyFilter = wf.NotifyFilter Or IO.NotifyFilters.FileName
wf.NotifyFilter = wf.NotifyFilter Or IO.NotifyFilters.Attributes

These statements cause the "FileSystemWatcher" to change more then once for a single change on the file.

Instead use this ....
wf.NotifyFilter = IO.NotifyFilters.FileName
wf.NotifyFilter = IO.NotifyFilters.Attributes

Also, the programmer needs to decide what kind of event to watch for ie. "Change" or "Created". I would not use both for the same "FileSystemWatcher" class.

I used the "wf.NotifyFilter = IO.NotifyFilters.LastAccess" instead of Jain's example because it still detect the events without the "change" events occuring mupliple times.

Keep intouch and I will continue to look for your comments.

Below is what I had came up with...

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
wf = New System.IO.FileSystemWatcher

On Error Resume Next
wf.Path = Me.txtWatchPath.Text
wf.Filter = Me.txtBoxFilter.Text
wf.NotifyFilter = IO.NotifyFilters.LastAccess Or IO.NotifyFilters.FileName

' add the handler to each event
AddHandler wf.Changed, AddressOf logChange

' add the rename handler as the signature is different
AddHandler wf.Renamed, AddressOf logRename
AddHandler wf.Error, AddressOf errorlogChange

On Error Resume Next
If Me.chkWatchsubDirecties.Checked = True Then
wf.IncludeSubdirectories = True
Else
wf.IncludeSubdirectories = False
End If

wf.EnableRaisingEvents = True

Me.btnStart.Enabled = False
Me.btnStop.Enabled = True
Me.txtBoxFilter.ReadOnly = True

' Turn off the update of the display on the click of the control.
Me.chkWatchsubDirecties.AutoCheck = False
End Sub

Private Sub errorlogChange(ByVal source As Object, ByVal e As ErrorEventArgs)
Dim sMessages As String
' Show that an error has been detected.
If TypeOf e.GetException Is InternalBufferOverflowException Then
Me.txtFolderActivity.Text &= ( _
"The file system watcher experienced an internal buffer overflow: " _
+ e.GetException.Message)
End If
End Sub

Private Sub logChange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
If e.ChangeType = IO.WatcherChangeTypes.Changed Then
' Specify what is done when a file is changed, created, or deleted.
Me.txtFolderActivity.Text &= "File name is: " + e.FullPath & " has been changed" & _
" @" & TimeString & ControlChars.NewLine
End If

'If e.ChangeType = WatcherChangeTypes.Created Then
' Me.txtFolderActivity.Text &= "File name is: " + e.FullPath & " has been created" & ControlChars.NewLine
'End If

'If e.ChangeType = WatcherChangeTypes.Deleted Then
' Me.txtFolderActivity.Text &= "File name is: " + e.FullPath & " has been deleted" & ControlChars.NewLine
'End If
End Sub

Private Sub logRename(ByVal source As Object, ByVal e As System.IO.RenamedEventArgs)
Me.txtFolderActivity.Text &= ("File: " & e.OldName & " has been renamed to: " & e.Name & " " & ControlChars.NewLine)
End Sub




Dave
GeneralRe: Controlling FileSystemWatcher Pin
DSAlbin24-May-06 12:22
DSAlbin24-May-06 12:22 
QuestionDataGrid Control Pin
Quecumber2569-May-06 10:27
Quecumber2569-May-06 10:27 
Questionhandler problem Pin
meconomou9-May-06 8:18
meconomou9-May-06 8:18 
Questioncombo box Data source Nothing Problem Pin
Hkothari779-May-06 8:02
Hkothari779-May-06 8:02 
AnswerRe: Data source Still Nothing Problem Pin
Hkothari779-May-06 8:04
Hkothari779-May-06 8:04 
QuestionHow to cut part of the piture in a picture box Pin
Murtuza Husain Miyan Patel9-May-06 7:58
professionalMurtuza Husain Miyan Patel9-May-06 7:58 
AnswerRe: How to cut part of the piture in a picture box Pin
Christian Graus9-May-06 10:39
protectorChristian Graus9-May-06 10:39 
QuestionAdding nodes to a treeview control Pin
Raistlin21_459-May-06 7:25
Raistlin21_459-May-06 7:25 
AnswerRe: Adding nodes to a treeview control Pin
digicd19-May-06 16:22
digicd19-May-06 16:22 
GeneralRe: Adding nodes to a treeview control Pin
Raistlin21_4510-May-06 6:01
Raistlin21_4510-May-06 6:01 
AnswerRe: Adding nodes to a treeview control Pin
Hacknight949-May-06 20:37
Hacknight949-May-06 20:37 
GeneralRe: Adding nodes to a treeview control Pin
Raistlin21_4510-May-06 6:05
Raistlin21_4510-May-06 6:05 
GeneralRe: Adding nodes to a treeview control Pin
Hacknight9410-May-06 14:15
Hacknight9410-May-06 14:15 
GeneralRe: Adding nodes to a treeview control Pin
Hacknight9410-May-06 14:21
Hacknight9410-May-06 14:21 
Questionfrom ADO to ADO.NET 2.0 Pin
Gulfraz Khan9-May-06 6:11
Gulfraz Khan9-May-06 6:11 
QuestionHandling Complex Numbers Pin
crtwrght_mrk9-May-06 6:09
crtwrght_mrk9-May-06 6:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.