Creates a temp file based on the given file being replaced and when a call to Commit() is made the target file is replaced with the current contents of the temporary file.
Syntax
Visual Basic (Declaration) | |
---|
Public Function New( _
ByVal targetName As String _
) |
Parameters
- targetName
Example
Library/Library.Test/TestReplaceFile.cs
C# | Copy Code |
---|
string testdata = Guid.NewGuid().ToString();
using (TempFile replace = new TempFile())
using (TransactFile temp = new TransactFile(replace.TempPath))
{
temp.WriteAllText(testdata);
Assert.IsTrue(temp.Exists);
temp.Rollback();
Assert.IsFalse(temp.Exists);
} |
VB.NET | Copy Code |
---|
Dim testdata As String = Guid.NewGuid().ToString()
Using replace As New TempFile()
Using temp As New TransactFile(replace.TempPath)
temp.WriteAllText(testdata)
Assert.IsTrue(temp.Exists)
temp.Rollback()
Assert.IsFalse(temp.Exists)
End Using
End Using |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also