DisposableTempFile Class |
Namespace: Atalasoft.Shared.IO
The DisposableTempFile type exposes the following members.
Name | Description | |
---|---|---|
DisposableTempFile |
Creates a new temporary file which uses a Guid as the name.
| |
DisposableTempFile(String) |
Creates a new temporary file which uses a Guid as the name.
| |
DisposableTempFile(String, String) |
Creates a new DisposableTempFile which uses a Guid as the name.
| |
DisposableTempFile(String, String, Boolean) |
Initializes a new instance of the DisposableTempFile class.
| |
DisposableTempFile(String, String, String) |
Initializes a new instance of the DisposableTempFile class.
| |
DisposableTempFile(String, String, String, Boolean) |
Initializes a new instance of the DisposableTempFile class.
|
Name | Description | |
---|---|---|
FullName |
Gets the full file name that was generated for this instance.
| |
IsCreated |
Gets a value indicating whether the file has been created.
Sets a value which if true, will create the file (If it hasn't already been created) else will delete the file (If it has been created).
|
Name | Description | |
---|---|---|
Create |
Creates / overwrites the temporary file.
| |
Delete |
Delete the temporary file.
| |
Dispose | Releases all resources used by the DisposableTempFile | |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | (Overrides ObjectFinalize.) | |
FromName |
Creates a DisposableTempFile from a known full path to a file.
| |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
Open |
Opens the temporary file with the specified mode, access and share.
| |
OpenRead |
Opens the temporary file for reading. Requires that IsCreated is true.
| |
OpenWrite |
Opens the temporary file for writing. Requires that IsCreated is true.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
String fullName = null; // Prepares a new temporary .txt file located in a subdirectory called "MySubFolder" within the system temp directory. using(DisposableTempFile tempFile = new DisposableTempFile("MySubFolder\\", ".txt")) { // Stores the full name that was generated for the temp file. fullName = tempFile.FullName; // Creates the temp file. tempFile.IsCreated = true; // Writes the byte '42' using(Stream stream = tempFile.OpenWrite()) { stream.WriteByte(42); } // Opens the same temp file that was just written for read. using(Stream stream = tempFile.OpenRead()) { // This should pass... (Reads first byte, ensures it is 42). Debug.Assert(stream.ReadByte() == 42); } } // Disposes tempFile. // This should also pass... (Demonstrates that after TemporaryFile is disposed, the file is deleted). Debug.Assert(File.Exists(fullName) == false);