The ItemCompletion event is raised each time a FileSystemItem object has been completely processed by a method call, providing progression information to the handler and the ability to perform custom post-processing on the target item.
Purpose
The ItemCompletion event provides a convenient way to perform custom actions on items being processed in a method call like CopyTo() or MoveTo() for example.
When the event is triggered, all actions of the source and target items have been completed.
Basic steps
To subscribe to the ItemProgression event, the following steps must be performed:
staticvoid ItemCompletionExample()
{
/* Create a reference to a FileSystemEvents object */
FileSystemEvents events = new FileSystemEvents();
/* Subscribe to the ItemCompletion event of the FileSystemEvents object using the ItemProgressionEventHandler delegate */
events.ItemCompletion += new ItemProgressionEventHandler( OnItemCompletion );
// Get a reference to an existing zip file
AbstractFile zipFile = new DiskFile( "ItemCompletionExample.zip" );
System.Diagnostics.Debug.Assert( zipFile.Exists );
Xceed.Zip.ZipArchive zip = new Xceed.Zip.ZipArchive( zipFile );
// Select an output folder
AbstractFolder destination = new DiskFolder( "Output" );
// Extract the files from the archive using the events object
zip.CopyFilesTo( events, null, destination, true, true );
}
/* Create a new method that will handle the events that are raised. For the purposes of this example, we will call the method OnItemProgression */staticvoid OnItemCompletion( object sender, ItemProgressionEventArgs e )
{
/* Place the desired code in the newly created event handler */
FileSystemItem targetItem = e.TargetItem;
// Remove the read-only attribute from the target file
FileAttributes attributes = targetItem.Attributes;
targetItem.Attributes = ( attributes & ~FileAttributes.ReadOnly );
}
PrivateSharedSub ItemCompletionExample()
' Create a reference to a FileSystemEvents object
Dim events AsNew FileSystemEvents()
' Subscribe to the ItemCompletion event of the FileSystemEvents object using the ItemProgressionEventHandler delegate
AddHandler events.ItemCompletion, AddressOf OnItemCompletion
' Get a reference to an existing zip file
Dim zipFile As AbstractFile = New DiskFile("ItemCompletionExample.zip")
System.Diagnostics.Debug.Assert(zipFile.Exists)
Dim zip AsNew Xceed.Zip.ZipArchive(zipFile)
' Select an output folder
Dim destination As AbstractFolder = New DiskFolder("Output")
' Extract the files from the archive using the events object
zip.CopyFilesTo(events, Nothing, destination, True, True)
End Sub' Create a new method that will handle the events that are raised. For the purposes of this example, we will call the method OnItemProgression
PrivateSharedSub OnItemCompletion(ByVal sender AsObject, ByVal e As ItemProgressionEventArgs)
' Place the desired code in the newly created event handler
Dim targetItem As FileSystemItem = e.TargetItem
' Remove the read-only attribute from the target file
Dim attributes As FileAttributes = targetItem.Attributes
targetItem.Attributes = (attributes And (Not FileAttributes.ReadOnly))
End Sub