FileSystemWatcher.Renamed : FileSystemWatcher « System.IO « VB.Net by API

Home
VB.Net by API
1.Microsoft.VisualBasic
2.Microsoft.Win32
3.System
4.System.Collections
5.System.Collections.Generic
6.System.Collections.Specialized
7.System.ComponentModel
8.System.Configuration.ConfigurationSettings
9.System.Data
10.System.Data.Odbc
11.System.Data.OleDb
12.System.Data.OracleClient
13.System.Data.SqlClient
14.System.Diagnostics
15.System.Drawing
16.System.Drawing.Drawing2D
17.System.Drawing.Imaging
18.System.Drawing.Printing
19.System.Drawing.Text
20.System.Globalization
21.System.IO
22.System.IO.IsolatedStorage
23.System.IO.Ports
24.System.Media
25.System.Messaging
26.System.Net
27.System.Net.Sockets
28.System.Reflection
29.System.Runtime.InteropServices
30.System.Runtime.Remoting.Channels
31.System.Runtime.Serialization
32.System.Runtime.Serialization.Formatters.Binary
33.System.Runtime.Serialization.Formatters.Soap
34.System.Security.Cryptography
35.System.Security.Cryptography.X509Certificates
36.System.Security.Permissions
37.System.Security.Principal
38.System.ServiceProcess
39.System.Text
40.System.Text.RegularExpressions
41.System.Threading
42.System.Web
43.System.Web.Mail
44.System.Windows.Forms
45.System.Xml
46.System.Xml.Schema
47.System.Xml.Serialization
48.System.Xml.Xsl
VB.Net
VB.Net Tutorial
VB.Net by API » System.IO » FileSystemWatcher 
FileSystemWatcher.Renamed
  


Imports System.IO

Imports System.Windows.Forms

public class FileSystemWatcherDemo
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

Public Class Form1
    Inherits System.Windows.Forms.Form

    Public Sub New()
        MyBase.New()

        InitializeComponent()
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is NothingThen
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    Private components As System.ComponentModel.IContainer

    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents txtPath As System.Windows.Forms.TextBox
    Friend WithEvents txtFile As System.Windows.Forms.TextBox
    Friend WithEvents txtWatcher As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents btnWatch As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.txtPath = New System.Windows.Forms.TextBox()
        Me.txtFile = New System.Windows.Forms.TextBox()
        Me.txtWatcher = New System.Windows.Forms.TextBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.btnWatch = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif"12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me.Label1.Location = New System.Drawing.Point(5120)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(10316)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "File Watcher"
        '
        'Label2
        '
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif"12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me.Label2.Location = New System.Drawing.Point(5152)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(10316)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "File Type"
        '
        'txtPath
        '
        Me.txtPath.Font = New System.Drawing.Font("Microsoft Sans Serif"10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me.txtPath.Location = New System.Drawing.Point(16416)
        Me.txtPath.Name = "txtPath"
        Me.txtPath.Size = New System.Drawing.Size(65523)
        Me.txtPath.TabIndex = 2
        Me.txtPath.Text = "C:\Temp\test\"
        '
        'txtFile
        '
        Me.txtFile.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me.txtFile.Location = New System.Drawing.Point(164, 48)
        Me.txtFile.Name = "txtFile"
        Me.txtFile.Size = New System.Drawing.Size(133, 23)
        Me.txtFile.TabIndex = 3
        Me.txtFile.Text = "*.txt"
        '
        'txtWatcher
        '
        Me.txtWatcher.Location = New System.Drawing.Point(51, 104)
        Me.txtWatcher.Multiline = True
        Me.txtWatcher.Name = "txtWatcher"
        Me.txtWatcher.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.txtWatcher.Size = New System.Drawing.Size(778, 224)
        Me.txtWatcher.TabIndex = 5
        Me.txtWatcher.Text = ""
        '
        'Label3
        '
        Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me.Label3.Location = New System.Drawing.Point(51, 80)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(103, 16)
        Me.Label3.TabIndex = 6
        Me.Label3.Text = "Message"
        '
        'btnWatch
        '
        Me.btnWatch.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
        Me.btnWatch.Location = New System.Drawing.Point(625, 64)
        Me.btnWatch.Name = "btnWatch"
        Me.btnWatch.Size = New System.Drawing.Size(194, 32)
        Me.btnWatch.TabIndex = 7
        Me.btnWatch.Text = "Start"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(870, 357)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnWatch, Me.Label3, Me.txtWatcher, Me.txtFile, Me.txtPath, Me.Label2, Me.Label1})
        Me.ResumeLayout(False)

    End Sub

    Dim WithEvents FSWatcher As New FileSystemWatcher()

    Private Sub btnWatch_Click _
      (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWatch.Click
        Dim strPathWatch As String
        Dim strFileWatch As String
        strPathWatch = txtPath.Text
        strFileWatch = txtFile.Text
        FSWatcher.Path = strPathWatch
        FSWatcher.Filter = strFileWatch
        FSWatcher.IncludeSubdirectories = True
        FSWatcher.NotifyFilter = _
          NotifyFilters.LastWrite Or NotifyFilters.FileName
        FSWatcher.EnableRaisingEvents = True
        txtWatcher.Text += vbCrLf + "Start:"

    End Sub

    Private Sub FSWatcher_Changed(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FSWatcher.Changed
        WatchMessage(e.FullPath, e.ChangeType.ToString)
    End Sub

    Private Sub FSWatcher_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FSWatcher.Created
        WatchMessage(e.FullPath, e.ChangeType.ToString)
    End Sub

    Private Sub FSWatcher_Deleted(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FSWatcher.Deleted
        WatchMessage(e.FullPath, e.ChangeType.ToString)
    End Sub

    Private Sub FSWatcher_Error(ByVal sender As Object, ByVal e As System.IO.ErrorEventArgs) Handles FSWatcher.Error
        WatchMessage("", e.GetException.Message)
    End Sub


    Private Sub FSWatcher_Renamed(ByVal sender As Object, ByVal e As System.IO.RenamedEventArgs) Handles FSWatcher.Renamed
        WatchMessage(e.FullPath, e.ChangeType.ToString)
    End Sub

    Private Sub WatchMessage(ByVal strpFileName As String, ByVal strpMessage As String)
        Dim strMessage As String
        strMessage =  strpFileName + " " + strpMessage
        txtWatcher.Text += vbCrLf + strMessage

    End Sub
End Class

   
    
  
Related examples in the same category
1.FileSystemWatcher.Changed
2.FileSystemWatcher.Created
3.FileSystemWatcher.Deleted
4.FileSystemWatcher.EnableRaisingEvents
5.FileSystemWatcher.Filter
6.FileSystemWatcher.IncludeSubdirectories
7.FileSystemWatcher.NotifyFilter
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.