Xceed .NET Libraries Documentation
Welcome to Xceed Data Manipulation Compoents for .NET and .NET Standard / Task-Based Help / FTP capabilities / Working with classes from the Xceed.FileSystem namespace / Removing items from a local folder

In This Topic
    Removing items from a local folder
    In This Topic

    Items can be deleted using the Delete method. With the Xceed FileSystem, a folder is a folder regardless of if it is located on a local disk, in a zip file, in memory, or on an FTP server. 

    The following example demonstrates how to delete a file on a local drive using the steps listed below:

    1. Create an instance of a DiskFile which will represent the file on the local drive to delete. 

    2. Verify if the file exists prior to deleting it using the Exists property. If an attempt is made to delete a file that does not exist, an exception will be thrown. 

    3. Delete the file by calling its Delete method

    VB.NET Copy Code

    Imports Xceed.FileSystem

    Dim file As New DiskFile( "c:\test.txt" )

    If file.Exists Then
      file.Delete()
    End If

    C# Copy Code

    using Xceed.FileSystem;

    DiskFile file = new DiskFile( "c:\\test.txt" );

    if( file.Exists )
      file.Delete();

    Events

    All methods exposed by the Xceed FileSystem's FileSystemItem, AbstractFolder, AbstractFile, and derived classes have an overload that can be used when events are required. Events can be handled by creating an instance of the FileSystemEvents class and subscribing to the desired events. For example:

    VB.NET Copy Code

    Imports Xceed.FileSystem

    Dim file As New DiskFile("c:\test.txt")
    Dim events As New FileSystemEvents()
    AddHandler events.ByteProgression, AddressOf Me.byte_progression

    If file.Exists Then
      file.Delete( events, Nothing )
    End If

    RemoveHandler events.ByteProgression, AddressOf Me.byte_progression

    Private Sub byte_progression(ByVal sender As Object, ByVal e As ByteProgressionEventArgs)
      System.Diagnostics.Debug.WriteLine(e.CurrentFileBytes.Percent.ToString())
    End Sub

    C# Copy Code
    using Xceed.FileSystem;
     
    DiskFile file = new DiskFile( @"c:\test.txt" );
    FileSystemEvents events = new FileSystemEvents();
    events.ByteProgression += new ByteProgressionEventHandler( this.byte_progression );
     
    if( file.Exists )
      file.Delete( events, null );
     
    events.ByteProgression -= new ByteProgressionEventHandler( this.byte_progression );
     
    private void byte_progression( object sender, ByteProgressionEventArgs e )
    {
      System.Diagnostics.Debug.WriteLine( e.CurrentFileBytes.Percent.ToString() );
    }

    Things to consider

    • Do you want to display progress information? Create an instance of the FileSystemEvents class and handle the ByteProgression and/or ItemProgression events. 

    • Do you want to display progress information when a folder is being scanned? Create an instance of the FileSystemEvents class and handle the ScanningFolder event. 

    • Do you want to intervene when an error occurs with one or more of the items being manipulated? Create an instance of the FileSystemEvents class and handle the ItemException event.