file notification


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

Who is Participating?
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);
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.