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.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.