1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/// <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 { }
}
}
|