VB.Net
  Home arrow VB.Net arrow Page 2 - Watching Folder Activity in VB.NET
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VB.NET

Watching Folder Activity in VB.NET
By: Jayesh Jain
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 54
    2002-10-13

    Table of Contents:
  • Watching Folder Activity in VB.NET
  • Getting Started
  • Building Our Application (contd.)
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Watching Folder Activity in VB.NET - Getting Started


    (Page 2 of 4 )

    Open Visual Studio .NET and create a new Windows Application Project. Call it WatchFolder and click OK:

    Creating our application

    Create a user interface as shown in the image below:

    Creating our user interface

    Add the following controls to our form:
    • txt_watchpath: TextBox (for folder path)
    • btn_startwatch: Button (start watching)
    • btn_stop: Button (stop watching)
    • txt_folderactivity: Textbox (folder activity)
    Lets start coding for this application. The first thing we need to do is to import the required classes. Type the following code before your class declaration:

    Imports System.IO
    Imports System.Diagnostics


    This code will import the necessary class required for our application. We also need to declare a public variable for our FileSystemWatcher class:

    Public watchfolder As FileSystemWatcher

    Add the following code to the btn_start_click procedure:

    watchfolder = New System.IO.FileSystemWatcher()

    'this is the path we want to monitor
    watchfolder.Path = txt_watchpath.Text

    'Add a list of Filter we want to specify
    'make sure you use OR for each Filter as we need to
    'all of those

    watchfolder.NotifyFilter = IO.NotifyFilters.DirectoryName
    watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _
    IO.NotifyFilters.FileName
    watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _
    IO.NotifyFilters.Attributes

    ' add the handler to each event
    AddHandler watchfolder.Changed, AddressOf logchange
    AddHandler watchfolder.Created, AddressOf logchange
    AddHandler watchfolder.Deleted, AddressOf logchange

    ' add the rename handler as the signature is different
    AddHandler watchfolder.Renamed, AddressOf logrename

    'Set this property to true to start watching
    watchfolder.EnableRaisingEvents = True

    btn_startwatch.Enabled = False
    btn_stop.Enabled = True

    'End of code for btn_start_click


    The NotifyFilter propery is used to specify the types of changes that we want to watch. You can combine the notify filters to watch for one or more types of changes. For example, set the NotifyFilter property to Size if you want to monitor the changes in the file/folder size.

    There are many NotifyFilter properties that you can set. Here’s the complete list:
    • Attributes: The attributes of the file or folder
    • CreationTime: The time the file or folder was created
    • DirectoryName: The name of the directory
    • FileName: The name of the file
    • LastAccess: The date the file or folder was last opened
    • LastWrite: The date the file or folder last had anything written to it
    • Security: The security settings of the file or folder
    • Size: The size of the file or folder
    The default is the bitwise OR combination of LastWrite, FileName, and DirectoryName.

    More VB.Net Articles
    More By Jayesh Jain


     

    VB.NET ARTICLES

    - MyClass - Implementing Polymorphism in VB.Net
    - Building a News Ticker Using VB.Net
    - Everything You Wanted to Know About Forms In...
    - Building Assemblies with VB.Net
    - Simple VB.NET Notify Icon with Panel Applica...
    - Regular Expressions in .NET
    - String Encryption With Visual Basic .NET
    - Deploying Applications in VB.NET: Part 1/2
    - Watching Folder Activity in VB.NET
    - Creating A Windows Service in VB.NET
    - Implementing The Google Web Service In VB.NET
    - Migrating to Visual Basic.NET from Visual Ba...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway