Click or drag to resize
TempFileManager Class
Creates and manages a tempoary file ensuring that it is deleted when no longer required.
Inheritance Hierarchy
SystemObject
  Sdl.FileTypeSupport.FrameworkTempFileManager

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 TempFileManager : IDisposable

The TempFileManager type exposes the following members.

Constructors
  NameDescription
Public methodTempFileManager
Creates a temp file with a random name and manages it. See TempFileManager(String, Boolean) for more details.
Public methodTempFileManager(String)
Creates the named temp file in a random temp directory or named sub-directory and manages it. See TempFileManager(String, Boolean) for more details.
Public methodTempFileManager(String, Boolean)
Creates a temp file and manages it.
Top
Methods
  NameDescription
Public methodStatic memberAutoDeleteNonLockedFiles
Deletes all TempFileManager managed tempoary files and tempoary folders that could not be deleted previously.
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 methodStatic memberTakeOverManagedFile
This method handles the logic of handing over the management of a TempFileManager managed file to a new managed file
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Properties
  NameDescription
Public propertyCancelDelete
If true then this managed 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.
Public propertyFileProcess
Can be set to a running process' Process instance so that the managed temp file is deleted when the process exits.
Public propertyLocked
Set to create (if it does not exist) and then to lock the temp file. The locked FileStream is available from LockedFileStream.
Public propertyLockedFileStream
Returns the locked FileStream instace if the temp file was previously locked by setting Locked.
Public propertyReadOnly
If set to true the managed temp file's readonly file system flag is set.
Top
Remarks

The temp file's file system readonly flag can also be set using ReadOnly and also the file can be locked using Locked to prevent it being deleted by the user or any disk space management software.

This class uses the FileJanitor class so it provides a convenient way to create and manage session-scope temporary files. Make sure that all objects needing access to the temp file have access to a corresponding TempFileManager object, that way when it is no longer referenced by any live objects and it gets garbage collected the temporary file is deleted.

The class also implements the IDisposable interface, and deletes the FileJanitor managed file 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.

The TempFileManager class also has a static method AutoDeleteNonLockedFiles() that can be called during applicaiton startup to delete any temp files that may not have been deleted previously.

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