Results 1 to 5 of 5

Thread: [RESOLVED] [2005] content of a file

  1. #1

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    Resolved [RESOLVED] [2005] content of a file

    how can i set it so that once the content of a certain file (.txt) gets changed, an action gets executed
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] content of a file

    FileSystemWatcher

    Check out this. Probably the best way. Raises events when a file changes. Just put the code that you want to execute in the Changed event.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  3. #3

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    Re: [2005] content of a file

    ugh i hate the msdn library, i don't quite understand what they are saying...
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

  4. #4
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] content of a file

    It's not too bad.

    Simply create an instance of the FileSystemWatcher on a Form Load event for example:

    VB Code:
    1. Dim mywatcher As New IO.FileSystemWatcher  'Create new instance of FileSystemWatcher
    2.         mywatcher.Path = "D:\My Documents\"  'Specify Path to File or Directory. Which ever you need
    3.         mywatcher.NotifyFilter = IO.NotifyFilters.LastWrite Or IO.NotifyFilters.LastAccess Or IO.NotifyFilters.FileName
    4.         AddHandler mywatcher.Changed, AddressOf OnChanged
    5.         AddHandler mywatcher.Created, AddressOf OnChanged  'Add handlers to catch certain events of certain types
    6.         AddHandler mywatcher.Deleted, AddressOf OnChanged  'Use intellisense to see what others are open to you
    7.         mywatcher.EnableRaisingEvents = True     'Start the process


    This is the code operates/fires when an event is detected. You would probably place your code that you want to fire when a file changes.
    VB Code:
    1. Private Shared Sub OnChanged(ByVal source As Object, ByVal e As IO.FileSystemEventArgs)
    2.  
    3.         ' Specify what is done when a file is changed, created, or deleted.
    4.         'This is the event that detects a file change.
    5.         'Put your code in here
    6.         MessageBox.Show("File: " & e.FullPath & " " & e.ChangeType)
    7.  
    8.     End Sub
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  5. #5

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    Re: [2005] content of a file

    gee thanks a bunch

    i changed the "Private Shared Sub" to "Private Sub" as i don't want it throughout each form...

    thanks.
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width