Xceed .NET Libraries Documentation
ItemCompletion event
Welcome to Xceed .NET, .NET Standard and Xamarin Libraries! > Basic Concepts > Events > ItemCompletion event

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:

Demonstration

This example demonstrates how to use the ItemCompletion event to clear the "read only" attribute from files extracted from a zip archive.

static void 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 */
static void 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 );
}
Private Shared Sub ItemCompletionExample()
  ' Create a reference to a FileSystemEvents object 
  Dim events As New 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 As New 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 
Private Shared Sub OnItemCompletion(ByVal sender As Object, 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