Xceed .NET Libraries Documentation
ParsingListingLine event

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

The ParsingListingLine event is raised when a listing line is received from the FTP server. Contrary to other events which are subscribed to by creating an instance of a FileSystemEvents class, the ParsingListingLine event can only be subscribed to via the FtpConnection instance. If any other events are required, an instance of the FileSystemEvents class must be created and the desired events subscribed to. 

Xceed FTP for .NET currently provides automatic support for listing the contents of AS400, DOS (Windows), UNIX and VMS FTP servers when calling the GetItems, GetFiles, or GetFolders methods. To modify or manually parse the listing lines returned by the FTP server, the ParsingListingLine event can be used, or a new listing parser added to the FTP connection's ListingParsers collection .

Basic steps

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

  1. Create an instance of the FtpConnection class. 

  2. Subscribe to the ParsingListingLine event.

The following example demonstrates how use the ParsingListingLine event to manually parse the listing lines returned by an FTP server to remove the potential   "." and ".." items.

VB.NET Copy Code

Imports Xceed.FileSystem
Imports Xceed.Ftp

Dim connection As FtpConnection
Try
  connection = New FtpConnection( "ftp.server.com" )
  AddHandler connection.ParsingListingLine, AddressOf Me.parsing_listingline
  Dim folder As New FtpFolder(connection)
  folder.GetItems( True )

Finally
  RemoveHandler connection.ParsingListingLine, AddressOf Me.parsing_listingline
  connection.Dispose()
End Try

Private Sub parsing_listingline(ByVal sender As Object, ByVal e As ParsingListingLineEventArgs)
  If (e.Item.Name = ".") Or (e.Item.Name = "..") Then
    e.Valid = False
  Else
    System.Diagnostics.Debug.WriteLine(e.Item.Name)
  End If
End Sub

C# Copy Code
using Xceed.FileSystem;
using Xceed.Ftp;
using( FtpConnection connection = new FtpConnection( "ftp.server.com" ) )
{
  connection.ParsingListingLine += new ParsingListingLineEventHandler( this.parsing_listingline );
 
  FtpFolder folder = new FtpFolder( connection );
  folder.GetItems( true );       
 
  connection.ParsingListingLine -= new ParsingListingLineEventHandler( this.parsing_listingline );
}  
 
private void parsing_listingline( object sender, ParsingListingLineEventArgs   e )
{
  if( ( e.Item.Name == "." ) || ( e.Item.Name == ".." ) )
  {
    e.Valid = false;
  }
  else
  {
    System.Diagnostics.Debug.WriteLine( e.Item.Name );        
  }  
}

Custom line parsers

Usually, if you only want to modify or filter the listing lines returned by the GetItems, GetFiles, or GetFolders methods, you would handle the ParsingListingLine event rather than creating a listing parser. If however, you want to support the listing lines returned by an FTP server that is not automatically supported by Xceed FTP for .NET, then your best option would be to create a listing parser as it will make it easier to reuse your code. 

To create a custom listing parser, create a class that derives from the FtpListingParser class and override the ParseLine method. In the ParseLine method, parse the line that is received as a parameter to create and return a new FtpItemInfo object that contains the FTP item's information. Once you have your custom listing parser, add it to the FTP connection's ListingParsers collection.