[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

file notification

Posted on 2006-05-02
1
Medium Priority
?
238 Views
Last Modified: 2010-04-17
Hi,

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 c#.net?


Thanks
0
Comment
Question by:anup001
1 Comment
 

Accepted Solution

by:
gesman earned 1500 total points
ID: 16609366
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);
            }
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

834 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