Xceed .NET Libraries Documentation
Welcome to Xceed Data Manipulation Compoents for .NET and .NET Standard / Advanced Concepts / Extending / Extending the AbstractFolder class

In This Topic
    Extending the AbstractFolder class
    In This Topic

    The AbstractFolder class, as well as all the classes that derive from the AbstractFolder class, can be derived from to create custom folder classes.

    Basic Steps

    When creating a class that derives from the AbstractFolder class or one of its derived classes, the following functions must be implemented: 

    Method/Property Description
    DoGetChildItems Retrieves an array of FileSystemItem objects representing the child items of the folder.
    DoGetFile Retrieves a reference to an AbstractFile object contained within the folder.
    DoGetFolder Retrieves a reference to an AbstractFolder object contained within the folder.
    DoName Gets or sets the short name of the item.
    DoFullName Gets the full name of the item, including path.
    DoAttributes Gets or sets the attributes of the item. If your custom folder does not support attributes, override the DoHasAttributes property and return false. This will prevent the DoAttributes method from being called needlessly.
    DoCreationDateTime Gets or sets the creation date and time of the item. If your custom folder does not support having a creation date and time, override the DoHasCreationDateTime property and return false. This will prevent the DoCreationDateTime method from being called needlessly.
    DoLastWriteDateTime Gets or sets the modification date and time of the item. If your custom folder does not support having a last write date and time, override the DoHasLastWriteDateTime property and return false. This will prevent the DoLastWriteDateTime method from being called needlessly.
    DoLastAccessDateTime Gets or sets the last access date and time of the item. If your custom folder does not support having a last access date and time, override the DoHasLastAccessDateTime property and return false. This will prevent the DoLastAccessDateTime method from being called needlessly.
    DoParentFolder Gets a reference to the parent folder of this item.
    DoRootFolder Gets a reference to the root folder of this item.
    DoExists Gets a boolean value indicating if the item physically exists.
    DoRefresh Re-reads the information from the physical item.
    DoCreate Creates the physical item represented by the FileSystemItem object.
    DoDelete Permanently deletes the physical item.
    IsSameAs Gets a boolean value indicating if the source and target items are the same.
    IsPathRooted Returns a boolean value indicating if the path passed is rooted in the environment of the FileSystemItem object we are dealing with.

    Each of the overridden abstract "Do" methods and properties are called by their corresponding public counterparts and are responsible for executing the actual operation. The public method simply validates the parameters. It is the "Do" implementation that must make sure that the required conditions are met. For example, in order to call delete on an item, it must first exist. This means that your implementation of DoDelete must throw an ItemDoesNotExistException if the item does not exist.

    Template

    The following example demonstrates the minimum implementation required for a class that derives from the AbstractFile class.

    VB.NET Copy Code

    Imports System.IO
    Imports Xceed.FileSystem

    Namespace Xceed.FileSystem.Samples

      Public Class CustomFolder
        Inherits AbstractFolder

        Protected Overrides Function DoGetChildItems(ByVal session As FileSystemEventsSession) As FileSystemItem()
          Return Nothing
        End Function

        Protected Overrides Function DoGetFile(ByVal session As FileSystemEventsSession, ByVal fileName As String) As AbstractFile
          Return Nothing
        End Function

        Protected Overrides Function DoGetFolder(ByVal session As FileSystemEventsSession, ByVal folderName As String) As AbstractFolder
          Return Nothing
        End Function

        Protected Overrides Property DoName() As String
          Get
            Return Nothing
          End Get
          Set(ByVal Value As String)
          End Set
        End Property

        Protected Overrides ReadOnly Property DoFullName() As String
          Get
            Return Nothing
          End Get
        End Property

        Protected Overrides Property DoAttributes() As FileAttributes
          Get
            Return New FileAttributes()
          End Get
          Set(ByVal Value As FileAttributes)
          End Set
        End Property

        Protected Overrides Property DoCreationDateTime() As DateTime
          Get
            Return New DateTime()
          End Get
          Set(ByVal Value As DateTime)
          End Set
        End Property

        Protected Overrides Property DoLastWriteDateTime() As DateTime
          Get
            Return New System.DateTime()
          End Get
          Set(ByVal Value As DateTime)
          End Set
        End Property

        Protected Overrides Property DoLastAccessDateTime() As DateTime
          Get
            Return New DateTime()
          End Get
          Set(ByVal Value As DateTime)
          End Set
        End Property

        Protected Overrides ReadOnly Property DoParentFolder() As AbstractFolder
          Get
            Return Nothing
          End Get
        End Property

        Protected Overrides ReadOnly Property DoRootFolder() As AbstractFolder
          Get
            Return Nothing
          End Get
        End Property

        Protected Overrides ReadOnly Property DoExists() As Boolean
          Get
            Return True
          End Get
        End Property

        Protected Overrides Sub DoRefresh(ByVal session As FileSystemEventsSession)
        End Sub

        Protected Overrides Sub DoCreate(ByVal session As FileSystemEventsSession)
        End Sub

        Protected Overrides Sub DoDelete(ByVal session As FileSystemEventsSession)
        End Sub

        Protected Overrides Function IsSameAs(ByVal target As FileSystemItem) As Boolean
          Return True
        End Function

        Protected Overrides Function IsPathRooted(ByVal path As String) As Boolean
          Return True
        End Function

      End Class
    End Namespace

    C# Copy Code

    using System;
    using System.IO;
    using Xceed.FileSystem;

    namespace Xceed.FileSystem.Samples
    {
      public class CustomFolder : AbstractFolder
      {
        public CustomFolder()
        {
        }

        protected override FileSystemItem[] DoGetChildItems(FileSystemEventsSession session)
        {
          return null;
        }

        protected override AbstractFile DoGetFile(FileSystemEventsSession session, string fileName)
        {
          return null;
        }

        protected override AbstractFolder DoGetFolder(FileSystemEventsSession session, string folderName)
        {
          return null;
        }

        protected override string DoName
        {
          get { return null; }
          set { }
        }

        protected override string DoFullName
        {
          get { return null; }
        }

        protected override FileAttributes DoAttributes
        {
          get { return new FileAttributes(); }
          set { }
        }

        protected override DateTime DoCreationDateTime
        {
          get { return new DateTime(); }
          set { }
        }

        protected override DateTime DoLastWriteDateTime
        {
          get { return new System.DateTime(); }
          set { }
        }

        protected override DateTime DoLastAccessDateTime
        {
          get { return new DateTime(); }
          set { }
        }

        protected override AbstractFolder DoParentFolder
        {
          get { return null; }
        }

        protected override AbstractFolder DoRootFolder
        {
          get { return null; }
        }

        protected override bool DoExists
        {
          get { return true; }
        }

        protected override void DoRefresh(FileSystemEventsSession session)
        {

        }

        protected override void DoCreate(FileSystemEventsSession session)
        {

        }

        protected override void DoDelete(FileSystemEventsSession session)
        {

        }

        protected override bool IsSameAs(FileSystemItem target)
        {
          return true;
        }

        protected override bool IsPathRooted(string path)
        {
          return true;
        }
      }
    }