Class FileJanitor
Deletes the associated file when this object is finalized or disposed.
Implements
Inherited Members
Namespace: SdlSdl.FileTypeSupportFramework
Assembly: Sdl.FileTypeSupport.Framework.Core.dll
Syntax
public class FileJanitor : IDisposable
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.
Constructors
FileJanitor(string)
Associates the janitor with the specified file.
Declaration
public FileJanitor(string filePath)
Parameters
Type | Name | Description |
---|---|---|
string | filePath |
Properties
CancelDelete
If true
then this Janitored file is not deleted when this instance is disposed.
Declaration
public bool CancelDelete { get; set; }
Property Value
Type | Description |
---|---|
bool |
DeleteDirectoryIfEmpty
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.
Declaration
public bool DeleteDirectoryIfEmpty { get; set; }
Property Value
Type | Description |
---|---|
bool |
Deleted
If true
then this managed file was sucessfully deleted.
Declaration
public bool Deleted { get; }
Property Value
Type | Description |
---|---|
bool |
FilePath
Full path to the file to be deleted.
Declaration
public string FilePath { get; set; }
Property Value
Type | Description |
---|---|
string |
Methods
DeleteFile()
Delete the file, if possible. Also deletes the directory if it is empty and DeleteDirectoryIfEmpty is true.
Declaration
public virtual void DeleteFile()
Dispose()
Deletes the file, if it exists.
Declaration
public void Dispose()
Dispose(bool)
Implementation of the recommended dispose protocol. Deletes the file if possible.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | true if this method is called from IDisposable.Dispose() and false if called from Finalizer |
~FileJanitor()
Deletes the file, if possible.
Declaration
protected ~FileJanitor()