/// <summary>
/// Erzeugt eine temporäre Datei
/// </summary>
public class TemporaryFile : IDisposable
{
/// <summary>
/// Dateipfad
/// </summary>
public string FullPath { get; private set; }
/// <summary>
/// Erzeugt eine temporäre Datei
/// </summary>
/// <param name="ext">Mögliche Dateierweiterung</param>
public TemporaryFile(string ext = ".tmp")
{
if (ext == null) ext = ".tmp";
if (!ext.StartsWith(".")) ext = "." + ext;
string fullPath;
do
{
fullPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N") + ext);
} while (File.Exists(fullPath));
FullPath = fullPath;
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting
/// unmanaged resources.
/// </summary>
public void Dispose()
{
try
{
File.Delete(FullPath);
}
catch { }
}
}