Xceed .NET Libraries Documentation
DiskRequired event

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

The DiskRequired event is raised every time a new disk or split part is required.

Purpose

The DiskRequired event is used to provide the appropriate disk or zip part while creating, updating or unzipping spanned and/or split zip files. When dealing with split files, the DiskRequired event can be used to provide custom naming conventions, change the location where the split files are to be created (for example, having each split part in a different folder, or you could even have parts in memory and others on disk) and even change the size of each split part.

Basic steps - C#

To subscribe to the DiskRequired event, the following steps must be performed:

  • Create a reference to a ZipEvents object. 

  • Subscribe to the DiskRequired event of the ZipEvents object using the DiskRequiredEventHandler delegate class. 

  • Create a new method that will handle the events that are raised. For the purposes of this example, we will call the method OnDiskRequired. 

  • Place the desired code in the newly created event handler.

Basic steps - VB.NET

To subscribe to the DiskRequired event, the following steps must be performed:

  • Create a reference to a ZipEvents object using the WithEvents keyword. 

  • Select the DiskRequired event from the list of available methods in the newly instantiated ZipEvents object. This is done in the same manner as, for example, adding the DoubleClick event of a ListBox.

    You can also subscribe to the event using the AddHandler/AddressOf statement. 

  • Place the desired code in the newly added event handler.

Demonstration

The following example demonstrates how to create a spanned zip file.

VB.NET Copy Code

Imports Xceed.Zip
Imports Xceed.FileSystem

Dim source As New DiskFolder("c:\windows\fonts")

Dim WithEvents zipEvents As New ZipEvents()
AddHandler zipEvents.DiskRequired, AddressOf Me.OnDiskRequired

Dim zip As New ZipArchive(zipEvents, Nothing, New DiskFile("a:\test.zip"))
zip.AllowSpanning = true

source.CopyFilesTo( zipEvents, null, zip, true, true )

' This method will handle the DiskRequired events that are raised.
'
' The code contained within this method is the suggested implementation to use when spanning.
Private Sub OnDiskRequired(ByVal sender As Object, ByVal e As DiskRequiredEventArgs)
  If e.Action = DiskRequiredAction.Fail Then

    If MessageBox.Show("Disk #" + e.DiskNumber.ToString() + " is required.", "Disk Required", MessageBoxButtons.OKCancel) = DialogResult.OK Then
      e.Action = DiskRequiredAction.Continue
    Else
      e.Action = DiskRequiredAction.Fail
    End If
  End If
End Sub

C# Copy Code
 
using Xceed.Zip;
using Xceed.FileSystem;
 
DiskFolder source = new DiskFolder( @"c:\windows\fonts" );
 
ZipEvents zipEvents = new ZipEvents();
zipEvents.DiskRequired += new DiskRequiredEventHandler( this.OnDiskRequired );
 
ZipArchive zip = new ZipArchive( zipEvents, null, new DiskFile( @"a:\test.zip" ) );
zip.AllowSpanning = true;
 
source.CopyFilesTo( zipEvents, null, zip, true, true );
 
// This method will handle the DiskRequired events that are raised.
//
// The code contained within this method is the suggested implementation to use when spanning.
private void OnDiskRequired( object sender, DiskRequiredEventArgs e )
{   
  if( e.Action == DiskRequiredAction.Fail )
  {
    if( MessageBox.Show( "Disk #" + e.DiskNumber.ToString() + " is required.", "Disk Required", MessageBoxButtons.OKCancel ) == DialogResult.OK )
      e.Action = DiskRequiredAction.Continue;
    else
      e.Action = DiskRequiredAction.Fail;
  }
}