Returns the originally provided filename that is being replaced
Syntax
Visual Basic (Declaration) | |
---|
Public ReadOnly Property TargetFile As String |
C# | |
---|
public string TargetFile {get;} |
Example
Library/Library.Test/TestReplaceFile.cs
C# | Copy Code |
---|
string testdata = Guid.NewGuid().ToString();
string tmpPath;
using (TempFile replace = new TempFile())
{
using (TransactFile temp = new TransactFile(replace.TempPath))
{
Assert.AreEqual(temp.TargetFile, replace.TempPath);
tmpPath = temp.TempPath;
Assert.IsTrue(temp.Exists);
temp.WriteAllText(testdata);
//missing commit:
//temp.Commit();
}
Assert.AreEqual(0, replace.Length);
Assert.IsFalse(File.Exists(tmpPath));
//now for real
using (TransactFile temp = new TransactFile(replace.TempPath))
{
tmpPath = temp.TempPath;
Assert.IsTrue(temp.Exists);
temp.WriteAllText(testdata);
temp.Commit();
}
Assert.IsFalse(File.Exists(tmpPath));
Assert.AreEqual(testdata, replace.ReadAllText());
} |
VB.NET | Copy Code |
---|
Dim testdata As String = Guid.NewGuid().ToString()
Dim tmpPath As String
Using replace As New TempFile()
Using temp As New TransactFile(replace.TempPath)
Assert.AreEqual(temp.TargetFile, replace.TempPath)
tmpPath = temp.TempPath
Assert.IsTrue(temp.Exists)
'missing commit:
'temp.Commit();
temp.WriteAllText(testdata)
End Using
Assert.AreEqual(0, replace.Length)
Assert.IsFalse(File.Exists(tmpPath))
'now for real
Using temp As New TransactFile(replace.TempPath)
tmpPath = temp.TempPath
Assert.IsTrue(temp.Exists)
temp.WriteAllText(testdata)
temp.Commit()
End Using
Assert.IsFalse(File.Exists(tmpPath))
Assert.AreEqual(testdata, replace.ReadAllText())
End Using |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also