File Watcher
-
Monday, February 04, 2013 7:54 PM
Hi, All
I have a package works like:
check whether file in folder deleted, if it's deleted, execute next task.
but it doesn't work, please see code below.
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"C:\Test";
watcher.Filter = "*.txt";
watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.Size;
watcher.Deleted += new FileSystemEventHandler(OnDeleted);
watcher.EnableRaisingEvents = true;
Dts.TaskResult = (int)ScriptResults.Success;
}
public void OnDeleted(object source, FileSystemEventArgs e)
{
Dts.Variables["User::intTest"].Value = 1;
}as long as any file in the folder being deleted, set variable value = 1, and set a constraint value check whether
@[User::intTest] == 1, if so, execute next task, otherwise, keep checking folder, no further action.
the problem is , after delete the file, the constraint will not check the variable's value.
can somebody tell me what I should do ?
Thank you in advance.
All Replies
-
Monday, February 04, 2013 8:26 PMModerator
In order for the FileWatcher to work your script needs to be in a constant execution, but SSIS packages don't.
You need to create an auxiliary process say in form of a Windows Service to monitor the file system that would trigger the package.
There is also a WMI File Watcher component in the package which is a better practice than using the Script Task; alas, it fires only once, then you need to restart the package.
Arthur My Blog

- Marked As Answer by Leading120 Tuesday, February 05, 2013 4:19 PM
-
Tuesday, February 05, 2013 3:29 AM
These links may contain helpful information for you
http://www.codeproject.com/Articles/42212/WMI-and-File-System-Monitoring
and
https://sqlserverrider.wordpress.com/2011/10/10/file-watcher-ssis/
Thanks Ayyappan Thangaraj, http://SQLServerRider.wordpress.com
- Marked As Answer by Leading120 Tuesday, February 05, 2013 4:19 PM
-
Tuesday, February 05, 2013 4:06 AM
You can do it with WMI Event watcher task:
http://msdn.microsoft.com/en-us/library/ms141130.aspx
If you will define timeouts, no need to restarting packages.
- Marked As Answer by Leading120 Tuesday, February 05, 2013 4:19 PM

