c# - FileSystemWatcher IncludeSubdirectories not working on network share -
i'm attempting watch network share folders file added share indicate upload complete. wanted use filesystemwatcher monitor share , subdirectories trigger file, shown below.
filesystemwatcher fsw = new filesystemwatcher(share, triggerfilepattern); fsw.includesubdirectories = true; fsw.created += new filesystemeventhandler(oncreated); fsw.renamed += new renamedeventhandler(onrenamed); fsw.error += new erroreventhandler(onerror);
if file created @ root of share, event triggers. if file created within subdirectory of share, event not trigger, , don't error either.
if create new filesystemwatcher subdirectory, receive event when file created there. but, similar top level filesystemwatcher, won't events files created in further subdirectories.
if change network share local directory testing, work expected.
any ideas? have set wonky network share setting blocks recursive filesystemwatcher checks? can work around this, nice not have complicate code.
edit: saw didn't have full control under properties->security tab, thought it. able normal desired behavior on different share same visible permissions, i'm not knowing why specific share isn't working.
edit2: @ coworker's suggestion, added changed handler too. doesn't make sense me how file can changed without getting created first, but... i'm getting changed events on share in question when creating files in subdirectory. (and i'm still getting nothing when renaming them.) solves immediate problem, i'm going leave question open in case someone's able answer why that's happening.
try this
private static filesystemwatcher fw; static void main(string[] args) { fw = new filesystemwatcher(@"d:\folder_watch"); fw.includesubdirectories = true; fw.notifyfilter = notifyfilters.lastaccess | notifyfilters.lastwrite | notifyfilters.filename | notifyfilters.directoryname; fw.created += fw_created; fw.changed += fw_created; fw.renamed += fw_created; fw.filter = "*.*"; fw.enableraisingevents = true; new system.threading.autoresetevent(false).waitone(); } static void fw_created(object sender, filesystemeventargs e) { try { fw.enableraisingevents = false; //your code } { fw.enableraisingevents = true; } }
Comments
Post a Comment