1

I am using C# filesystemwatcher to monitor a folder for new files that are generated from two web sites running on the same machine. Sometimes new files trigger my event handler and sometimes they do not.

FileSystemWatcher watcher = new FileSystemWatcher
{
 Path = "c:/inetpub/websites/site1/PDF/Source",
 NotifyFilter = NotifyFilters.LastWrite,
 Filter = "*.*"
};
watcher.Changed += new FileSystemEventHandler(OnNewFileCreated);
watcher.EnableRaisingEvents = true; 

When I examine the properties of the new files, the only real difference is the Details->Owner which are set to the web site names.

The files from site1 are processed, but the files with site2 are not. I can copy and paste the site2 file in explorer and then it is acted on.

I can try moving the folder to a c:/temp folder but this did not make much sense to do so.

Are there any ideas on what is going on? Any tips will be appreciated.

Thanks - Steve

asked Aug 26, 2024 at 21:44
6
  • Have tried adding NotifyFilters.FileName to the filter? Do both acutally save files in the same exact folder, or some subfolder? If that's the case, add .IncludeSubdirectories = true Commented Aug 26, 2024 at 21:56
  • That's a quite unusual way for writing a path in Windows. But anyway: Does site2 do anything differently when writing those files? Are they closed properly? Commented Aug 27, 2024 at 6:08
  • @pop, please, subscribe watcher to Error event and log error, maybe it will help to understand the issue. And if I do not mistake, after any error in fsw he must be recreated, because it will stop firing events Commented Aug 27, 2024 at 15:31
  • @Jimi - yes, both sites write to the same folder, the base folder I am watching Commented Aug 27, 2024 at 23:06
  • @OlehIvanitskyy - I added the following lines (without any luck) watcher.Created += new FileSystemEventHandler(OnNewFileCreated); watcher.Error += new ErrorEventHandler(OnError); Commented Aug 27, 2024 at 23:08

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.