Posted on 2006-03-24
Last Modified: 2010-04-23
Why my  Me.txtDisplayFiles.Text does not display the path, name and time when a new file is added. It says only "modifiled"

Private Sub btnStartWatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartWatch.Click

        WatchFolder = New System.IO.FileSystemWatcher

        If Me.txtWatchPath.Text = Nothing Then

            MessageBox.Show("Please check file path ", "Path   " & Now, MessageBoxButtons.OK, _


            WatchFolder.Path = Trim(Me.txtWatchPath.Text)

            WatchFolder.NotifyFilter = IO.NotifyFilters.DirectoryName
            WatchFolder.NotifyFilter = NotifyFilters.FileName
            WatchFolder.NotifyFilter = NotifyFilters.Attributes

            AddHandler WatchFolder.Changed, AddressOf logchange
            AddHandler WatchFolder.Created, AddressOf logchange
            AddHandler WatchFolder.Deleted, AddressOf logchange

            AddHandler WatchFolder.Renamed, AddressOf logrename

            WatchFolder.EnableRaisingEvents = True
            btnStartWatch.Enabled = False
            btnStopWatch.Enabled = True

        End If


    End Sub

    Private Sub logchange(ByVal source As Object, ByVal e As _
        If e.ChangeType = IO.WatcherChangeTypes.Changed Then
            Me.txtDisplayFiles.Text &= e.Name & _
                                    " - modified" & Now & vbCrLf

        ElseIf e.ChangeType = IO.WatcherChangeTypes.Created Then
            Me.txtDisplayFiles.Text &= e.FullPath & _
                                     " - created" & vbCrLf

        ElseIf e.ChangeType = IO.WatcherChangeTypes.Deleted Then
            Me.txtDisplayFiles.Text &= e.FullPath & _
                                    "- deleted" & vbCrLf
        End If

    End Sub

    Public Sub logrename(ByVal source As Object, ByVal e As _
        Me.txtDisplayFiles.Text &= "File" & e.OldName & _
                      " has been renamed to " & e.Name & vbCrLf
    End Sub

    Private Sub btnStopWatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStopWatch.Click

        ' Stop watching the folder
        watchfolder.EnableRaisingEvents = False
        btnStartWatch.Enabled = True
        btnStopWatch.Enabled = False
    End Sub
Question by:VBdotnet2005
    LVL 14

    Accepted Solution

    If I look at your code I think you should OR your filters

    WatchFolder.NotifyFilter = IO.NotifyFilters.DirectoryName
                WatchFolder.NotifyFilter = NotifyFilters.FileName
                WatchFolder.NotifyFilter = NotifyFilters.Attributes
    WatchFolder.NotifyFilter = (IO.NotifyFilters.DirectoryName OR NotifyFilters.FileName OR  NotifyFilters.Attributes)

    Try if you got all the filters you need


    Author Comment

    That works. Thank you

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now