C# Class CK.Core.TemporaryFile

Small helper to automatically delete a temporary file. It is mainly a secure wrapper around GetTempFileName that creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file: the P:Path property exposes it.
Inheritance: IDisposable
Show file Open project: Invenietis/ck-core

Public Methods

Method Description
Detach ( ) : void

Detaches the temporary file: it will no more be automatically destroyed. When created short-lived (see FileAttributes.Temporary), this flag is not reset: the file will be destroyed by the Operating System on the bext reboot.

Dispose ( ) : void

Attempts to delete the temporary file.

TemporaryFile ( ) : System

Initializes a new short lived TemporaryFile.

TemporaryFile ( bool shortLived ) : System

Initializes a new TemporaryFile. When shortLived is true, the FileAttributes.Temporary is set on the file.

TemporaryFile ( bool shortLived, string extension ) : System

Initializes a new TemporaryFile with an extension. When shortLived is true, the FileAttributes.Temporary is set on the file. The file will have a name looking like : xxxx.tmp.extension

When extension is ".", the final path will end with a ".".

TemporaryFile ( string extension ) : System

Initializes a new short lived TemporaryFile with an extension - the file will have a name looking like : xxxx.tmp.extension

Private Methods

Method Description
DeleteFile ( ) : bool

Method Details

Detach() public method

Detaches the temporary file: it will no more be automatically destroyed. When created short-lived (see FileAttributes.Temporary), this flag is not reset: the file will be destroyed by the Operating System on the bext reboot.
public Detach ( ) : void
return void

Dispose() public method

Attempts to delete the temporary file.
public Dispose ( ) : void
return void

TemporaryFile() public method

Initializes a new short lived TemporaryFile.
public TemporaryFile ( ) : System
return System

TemporaryFile() public method

Initializes a new TemporaryFile. When shortLived is true, the FileAttributes.Temporary is set on the file.
public TemporaryFile ( bool shortLived ) : System
shortLived bool True to set the on the file.
return System

TemporaryFile() public method

Initializes a new TemporaryFile with an extension. When shortLived is true, the FileAttributes.Temporary is set on the file. The file will have a name looking like : xxxx.tmp.extension
When extension is ".", the final path will end with a ".".
public TemporaryFile ( bool shortLived, string extension ) : System
shortLived bool True to set the on the file.
extension string Optional extension of the file (example : '.png' and 'png' would both work).
return System

TemporaryFile() public method

Initializes a new short lived TemporaryFile with an extension - the file will have a name looking like : xxxx.tmp.extension
public TemporaryFile ( string extension ) : System
extension string The extension of the file (example : '.png' and 'png' would both work)
return System