file notification

Posted on 2006-05-02
Last Modified: 2010-04-17

For a project i am planing to do something like a registeration and requesting for particular file on the server thru client and then instant notifciation if there are any changes to the file to the client.

I am planning to use windows client and web services to do this.

Is this doable in

Question by:anup001
    1 Comment

    Accepted Solution

    There is a C# object, named FileSystemWatcher, that offers some of this functionality.
    Basically you specify the location to watch (directory), filespec to watch (or filename) and what kind of events your want to watch for (modify, delete, renamed, etc...) and you'll get events triggered every time the change occurs.
    Here is the snippet of code that does it. Also this runs locally , so you'll need to define a way to send this data to remote location.

                public void StartWatching ()
                      // Create a new FileSystemWatcher and set its properties.
                      watcher = new FileSystemWatcher();
                      watcher.Path = this.rtbDirsList.Text;

                      /* Watch for changes in LastAccess and LastWrite times, and
                         the renaming of files or directories. */
                      watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                            | NotifyFilters.FileName | NotifyFilters.DirectoryName;

                      // Which files to watch for.
                      watcher.Filter = "*.*";

                      // Add event handlers.
                      watcher.Changed += new FileSystemEventHandler(OnChanged);
                      watcher.Created += new FileSystemEventHandler(OnChanged);
                      watcher.Deleted += new FileSystemEventHandler(OnChanged);
                      watcher.Renamed += new RenamedEventHandler(OnRenamed);

                      // Begin watching.
                      watcher.EnableRaisingEvents = true;

                // Define the event handlers.
                private /* static */ void OnChanged(object source, FileSystemEventArgs e)
                      // Specify what is done when a file is changed, created, or deleted.
                      this.listBox1.Items.Add ("File: " +  e.FullPath + " " + e.ChangeType);

                private /* static */ void OnRenamed(object source, RenamedEventArgs e)
                      // Specify what is done when a file is renamed.
                      string s = "File: " + e.OldFullPath + " renamed to " + e.FullPath;
    ///                  this.listBox1.Items.Add ("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
                      this.listBox1.Items.Add (s);

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
    If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now