CSharpTest.Net
ReplaceFile Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace : ReplaceFile Class

Glossary Item Box

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. Use the TransactFile if you MUST be certain to succeed then Commit(), otherwise this implementation provides a 'good-enough' transaction and is optimized for larger files.

Syntax

Visual Basic (Declaration) 
Public Class ReplaceFile 
   Inherits TempFile
   Implements CSharpTest.Net.Interfaces.ITransactable 
C# 
public class ReplaceFile : TempFile, CSharpTest.Net.Interfaces.ITransactable  

Example

Library/Library.Test/TestReplaceFile.cs

C#Copy Code
string testdata = Guid.NewGuid().ToString();

using (TempFile replace = new TempFile())
using (ReplaceFile temp = new ReplaceFile(replace.TempPath))
{
    temp.WriteAllText(testdata);
    Assert.IsTrue(temp.Exists);
    temp.Rollback();
    Assert.IsFalse(temp.Exists);
}
VB.NETCopy Code
Dim testdata As String = Guid.NewGuid().ToString()

Using replace As New TempFile()
    Using temp As New ReplaceFile(replace.TempPath)
        temp.WriteAllText(testdata)
        Assert.IsTrue(temp.Exists)
        temp.Rollback()
        Assert.IsFalse(temp.Exists)
    End Using
End Using

Inheritance Hierarchy

System.Object
   CSharpTest.Net.IO.TempFile
      CSharpTest.Net.IO.ReplaceFile

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys