File Watcher : File System Watcher « File Directory « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » File Directory » File System WatcherScreenshots 
File Watcher
  
Imports System.IO
Imports System.Windows.Forms
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Watcher
    Inherits System.Windows.Forms.Form


    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.txtTypes = New System.Windows.Forms.TextBox
        Me.lstNewFiles = New System.Windows.Forms.ListBox
        Me.cmdStop = New System.Windows.Forms.Button
        Me.cmdStart = New System.Windows.Forms.Button
        Me.txtDir = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(1640)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(6012)
        Me.Label2.TabIndex = 13
        Me.Label2.Text = "File Types:"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(1616)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(4012)
        Me.Label1.TabIndex = 12
        Me.Label1.Text = "Path:"
        '
        'txtTypes
        '
        Me.txtTypes.Location = New System.Drawing.Point(7636)
        Me.txtTypes.Name = "txtTypes"
        Me.txtTypes.Size = New System.Drawing.Size(26421)
        Me.txtTypes.TabIndex = 11
        Me.txtTypes.Text = "*.xls"
        '
        'lstNewFiles
        '
        Me.lstNewFiles.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom_
                    Or System.Windows.Forms.AnchorStyles.Left_
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lstNewFiles.Location = New System.Drawing.Point(12108)
        Me.lstNewFiles.Name = "lstNewFiles"
        Me.lstNewFiles.Size = New System.Drawing.Size(328199)
        Me.lstNewFiles.TabIndex = 10
        '
        'cmdStop
        '
        Me.cmdStop.Location = New System.Drawing.Point(22868)
        Me.cmdStop.Name = "cmdStop"
        Me.cmdStop.Size = New System.Drawing.Size(11224)
        Me.cmdStop.TabIndex = 9
        Me.cmdStop.Text = "Stop Watching"
        '
        'cmdStart
        '
        Me.cmdStart.Location = New System.Drawing.Point(10868)
        Me.cmdStart.Name = "cmdStart"
        Me.cmdStart.Size = New System.Drawing.Size(11224)
        Me.cmdStart.TabIndex = 8
        Me.cmdStart.Text = "Start Watching"
        '
        'txtDir
        '
        Me.txtDir.Location = New System.Drawing.Point(7612)
        Me.txtDir.Name = "txtDir"
        Me.txtDir.Size = New System.Drawing.Size(26421)
        Me.txtDir.TabIndex = 7
        Me.txtDir.Text = "d:\orders"
        '
        'Watcher
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(352318)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.txtTypes)
        Me.Controls.Add(Me.lstNewFiles)
        Me.Controls.Add(Me.cmdStop)
        Me.Controls.Add(Me.cmdStart)
        Me.Controls.Add(Me.txtDir)
        Me.Font = New System.Drawing.Font("Tahoma"8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "Watcher"
        Me.Text = "Watcher"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents txtTypes As System.Windows.Forms.TextBox
    Friend WithEvents lstNewFiles As System.Windows.Forms.ListBox
    Friend WithEvents cmdStop As System.Windows.Forms.Button
    Friend WithEvents cmdStart As System.Windows.Forms.Button
    Friend WithEvents txtDir As System.Windows.Forms.TextBox

    Private WithEvents Watch As New FileSystemWatcher()

    Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles cmdStart.Click
        Watch.Path = txtDir.Text
        Watch.Filter = txtTypes.Text
        Watch.EnableRaisingEvents = True
    End Sub

    Private Sub cmdStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles cmdStop.Click
        Watch.EnableRaisingEvents = False
    End Sub
    Private Sub Watch_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgsHandles Watch.Created
        lstNewFiles.Invoke(New UpdateListDelegate(AddressOf UpdateList), e.Name)
    End Sub

    Private Delegate Sub UpdateListDelegate(ByVal name As String)
    Private Sub UpdateList(ByVal name As String)
        lstNewFiles.Items.Add("New file: " & Name)
    End Sub

End Class

   
    
  
Related examples in the same category
1.File System Watcher: file updated, created
2.File System Watcher: File Folder Created
w_w___w___.__j___a___va2___s__.__c_om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.