RE: Duplicate Events with FileSystemWatcher



Thanks for the replies. They are very helpful. Evidently monitoring file
system changes is more complcated than I thought. I thnk I can handle the
scenarios where multiple events are generated, now that I understand it.

I have another problem with Word files, and probably other Office
applications as well. If I open a word file in the folder I am monitoring
and make changes and save it, I do not see any events on the word file
itself, but rather everything happens on a temp file that is created.
Furthermore, if I make further changes and save them no further events are
generated. Any thoughts on this or do you know where I can find more
detailed information about how Word writes data?


--
Thanks,

Bill Manring

"Bill Manring" wrote:

> I am testing the FileSystemWatcher class for possible use in an application I
> am going to be writing. I have a simple test application that lets met
> browse to a folder and I am looking for a change event.
>
> I have two problems. First, when a file is copied into the folder, four
> change events fire. When I edit the file and save it, three change events
> fire. I am working with plain text files being edited in NotePad. I really
> just want to get one event that tells me when a file has been changed, or
> when a new file is copied into the folder.
>
> I am including the relavent code below. I would appreciate any suggestions
> anyone has or insights into how the FileSystemWatcher class works.
>
> private void cmdGetFolder_Click(object sender, System.EventArgs e)
> {
> this.folderBrowserDialog1.ShowDialog(this);
> this.txtDirectoryToMonitor.Text = this.folderBrowserDialog1.SelectedPath;
> FileSystemWatcher objWatcher = new FileSystemWatcher(
> this.folderBrowserDialog1.SelectedPath);
>
> objWatcher.NotifyFilter = NotifyFilters.LastWrite;
> objWatcher.Changed += new FileSystemEventHandler(OnChanged);
> objWatcher.EnableRaisingEvents = true;
>
> }
>
> private void OnChanged(object source, FileSystemEventArgs e)
> {
> ListViewItem objItem;
>
> // Add the event to a list view control
> // I was ignoring temp files when I tried this with Word documents
> // but that is another problem.
> if (e.FullPath.EndsWith(".tmp") == false)
> {
> objItem = new ListViewItem(e.FullPath);
> objItem.SubItems.Add(e.ChangeType.ToString());
> this.lvEvents.Items.Add(objItem);
> }
>
> }
> --
> Thanks,
>
> Bill Manring
>
.



Relevant Pages

  • Re: FileSystemWatcher advice required please
    ... drop multiple files into a folder, they are created one at a time. ... you may have one event handler trying to perform the same IO ... To me this is defeating the objective of the FileSystemWatcher. ...
    (microsoft.public.dotnet.framework)
  • Re: Multiple occurences of same code
    ... one, called by FileSystemWatcher, adds new files ... to a queue, and the other thread takes files from the queue and processes ... > I have an app that seems to be fine at the moment, ... > the code is that a FileSystemWatcher keeps an eye on a folder, ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: I am storing some select files and folders path in my database.
    ... I have tried with FilesystemWatcher. ...     public static void Main ... pasted files or folder which can be picked up by an application in C# ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: ASP.NET Application and FileSystemWatcher
    ... >> just a timer and System.IO to check and keep track of the contents of the ... executed at a time interval for changes in an specific folder? ... >> way even if the application is in idle mode and filesystemWatcher is down ... >>> Sometimes the elephant eats you. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Counting file handles on a file
    ... > I am waiting for receipt of files in a directory. ... > FileSystemWatcher to detect when files arrive in said folder. ...
    (microsoft.public.dotnet.languages.csharp)