| TempFileManager Class |
Namespace: Sdl.FileTypeSupport.Framework
The TempFileManager type exposes the following members.
| Name | Description | |
|---|---|---|
| TempFileManager |
Creates a temp file with a random name and manages it.
See TempFileManager(String, Boolean) for more details.
| |
| TempFileManager(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.
| |
| TempFileManager(String, Boolean) |
Creates a temp file and manages it.
|
| Name | Description | |
|---|---|---|
| AutoDeleteNonLockedFiles |
Deletes all TempFileManager managed tempoary files and tempoary folders that could not be deleted previously.
| |
| Dispose |
Deletes the file, if it exists.
| |
| Dispose(Boolean) |
Implementation of the recommended dispose protocol. Deletes the file if possible.
| |
| Equals | (Inherited from Object.) | |
| Finalize |
Deletes the file, if possible.
(Overrides ObjectFinalize.) | |
| GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
| TakeOverManagedFile |
This method handles the logic of handing over the management
of a TempFileManager managed file to a new managed file
| |
| ToString | Returns a string that represents the current object. (Inherited from Object.) |
| Name | Description | |
|---|---|---|
| CancelDelete |
If true then this managed file is not deleted when this instance is disposed.
| |
| Deleted |
If true then this managed file was sucessfully deleted.
| |
| 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.
| |
| FilePath |
Full path to the file to be deleted.
| |
| FileProcess |
Can be set to a running process' Process instance so that the managed temp file is
deleted when the process exits.
| |
| Locked |
Set to create (if it does not exist) and then to lock the temp file.
The locked FileStream is available from LockedFileStream.
| |
| LockedFileStream |
Returns the locked FileStream instace if the temp file was previously locked by setting
Locked.
| |
| ReadOnly |
If set to true the managed temp file's readonly file system flag is set.
|
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.