# Easy and efficient way to log overwriting of a directory in SQL Server Integration Services (SSIS)

Recently I had the problem that I had a File System Task that moved a file but whenever the file was already there the package failed. So I set OverwriteDestination to TRUE. But now I lost complete control over which files were just moved and which did overwrite some already existing directory. My desired result was to get a message in my log file that some directory was overwritten by the FileSystemTask.

My first attempt was to google for a solution, but the only suggestions it came up with was how to overwrite a log file and not how to log that a file was overwritten.

### Use event handlers

Since I recently started working with Event Handlers I had the idea I could use one for this task. In general you could create a Script Task as part of the Control Flow (as we will create a Script Task anyway) but this is a much cleaner solution in my opinion. This small task is not a part of the Control Flow but rather really something that should be part of the PreExecution phase of the FileSystemTask.

To create an event handler:

1. Move to the tab Event Handlers
2. Select the executable (File System Task) and the event handler (OnPreExecute)

<rant>This tab is really not neatly arranged, why can’t there be a list of all event handlers somewhere?<\rant>

For the logic create a Script Task.

### Let a script task do the work

By double clicking on the script task you get to its edit windows. Choose the variables you want to pass to the C# script, in my case:

• FolderDestination
• LogFile_ConnectionString
• PackageName

Final words
Share this:TwitterFacebookPinterestGooglePrintLike this:Like Loading...