Xceed .NET Libraries Documentation
Welcome to Xceed Data Manipulation Compoents for .NET and .NET Standard / Basic Concepts / Events / ScanningFolder event

In This Topic
    ScanningFolder event
    In This Topic

    The ScanningFolder event is raised whenever a folder is scanned for matching items while building a list of items to process.

    Purpose

    The main purpose of the ScanningFolder event is to prevent your application from appearing frozen during long operations. For example, if you  were to handle the ByteProgression event in conjunction with the ScanningFolder event, the ScanningFolder event could return information on the folders being scanned during the first pass of the ByteProgression event.

    Basic steps - C#

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

    • Create a reference to a FileSystemEvents object. 

    • Subscribe to the ScanningFolder event of the FileSystemEvents object using the ScanningFolderEventHandler 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 OnScanningFolder. 

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

    Basic steps - VB.NET

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

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

    • Select the ScanningFolder event from the list of available methods in the newly instantiated FileSystemEvents 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

    This example demonstrates how to copy files to a folder located on disk and display progress information while the folder are being scanned.

    VB.NET Copy Code

    Imports Xceed.FileSystem

    Dim WithEvents fiEvents As New FileSystemEvents()
    Dim folder As New DiskFolder("c:\temp")

    folder.CopyFilesTo( fiEvents, Nothing, New DiskFolder( "c:\destination" ), True, True ) 

    Private Sub fiEvents_ScanningFolder( ByVal sender As Object, -
                                         ByVal e As Xceed.FileSystem.ScanningFolderEventArgs ) Handles fiEvents.ScanningFolder

      ListBox1.Items.Add("Scanning " + e.CurrentItem.Name)
    End Sub

    C# Copy Code
    using Xceed.FileSystem;
     
    FileSystemEvents fiEvents = new FileSystemEvents();
    fiEvents.ScanningFolder += new ScanningFolderEventHandler( OnScanningFolder );
     
    DiskFolder folder = new DiskFolder( @"c:\temp" );
    folder.CopyFilesTo( fiEvents, null, new DiskFolder( @"c:\destination" ), true, true );
     
    //This method will handle the ScanningFolder events that are raised.
    public static void OnScanningFolder( object sender, ScanningFolderEventArgs e )
    {
      Console.WriteLine( "Scanning " + e.CurrentItem.Name );
    }
     
    //If you no longer wish to handle the events that are raised,
    //you can unsubscribe from the event notifications by doing the following:
     
    fiEvents.ScanningFolder -= new ScanningFolderEventHandler( OnItemException );