Search code examples
vb.netfilterfilesystemwatchernotify

how to dynamically set Notify Filter for file system watcher in VB.NET


I have values being pulled from a database that specify if the user has selected a specific notify filter to be associated with the file system watcher. My question is if the user has specified multiple notify filters how to assign that to the watcher?

I understand the format of how the notify filter should be supplied I.E

fsw.NotifyFilter = NotifyFilters.FileName OR NotifyFilters.CreationTime OR ......

the problem is that i can assign each individual notify filter to the watcher using an if statement checking if the user has specified a certain notify filter and keep checking but that just sets the notify filter to the last checked value.

Using fsw.Notifyfilter += Notifyfilters.FileName does not work

Please Help


Solution

  • Ok, so you want something like this right?

    If condition Then
      fsw.NotifyFilter = (fsw.NotifyFilter Or NotifyFilters.FileName)
    Else If condition2 Then
      fsw.NotifyFilter = (fsw.NotifyFilter Or NotifyFilters.CreationTime)
    ...
    End If
    

    This is basically the equivalent of doing your OR'ing all at once, except broken down into multiple steps.