Click or drag to resize
FileJanitor Class
Deletes the associated file when this object is finalized or disposed.
Inheritance Hierarchy
SystemObject
  Sdl.FileTypeSupport.FrameworkFileJanitor

Namespace: Sdl.FileTypeSupport.Framework
Assembly: Sdl.FileTypeSupport.Framework.Core (in Sdl.FileTypeSupport.Framework.Core.dll) Version: 1.0.0.0 (1.0.2343.0)
Syntax
public class FileJanitor : IDisposable

The FileJanitor type exposes the following members.

Constructors
  NameDescription
Public methodFileJanitor
Associates the janitor with the specified file.
Top
Methods
  NameDescription
Public methodDeleteFile
Delete the file, if possible. Also deletes the directory if it is empty and DeleteDirectoryIfEmpty is true.
Public methodDispose
Deletes the file, if it exists.
Protected methodDispose(Boolean)
Implementation of the recommended dispose protocol. Deletes the file if possible.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Deletes the file, if possible.
(Overrides ObjectFinalize.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Properties
  NameDescription
Public propertyCancelDelete
If true then this Janitored file is not deleted when this instance is disposed.
Public propertyDeleted
If true then this managed file was sucessfully deleted.
Public propertyDeleteDirectoryIfEmpty
If true a check will be made after the file has been deleted, and if no other files exist in the same directory that directory will also be deleted.
Public propertyFilePath
Full path to the file to be deleted.
Top
Remarks

Provides a convenient way to manage session-scope temporary files. Make sure that all objects needing access to the file holds a reference to the corresponding FileJanitor object. When the file janitor is garbage collected or disposed the file is deleted.

The class also implements IDisposable interface. The file is deleted in the Dispose() implementation.

If the file for some reason cannot be deleted no error is raised.

Note that the .NET Framework does not guarantee that finalizers will be called, so there is always a possibility that the file does not get deleted.

See Also
Community
Edit
Be the first to Edit the community content of this topic.
Comments