CSharpTest.Net
TempDirectory Constructor()
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace > TempDirectory Class > TempDirectory Constructor : TempDirectory Constructor()

Glossary Item Box

Constructs a new temp directory with a newly created directory.

Syntax

Visual Basic (Declaration) 
Public Function New()
C# 
public TempDirectory()

Example

Library/Library.Test/TestTempFiles.cs

C#Copy Code
using(TempDirectory a = new TempDirectory())
using(TempDirectory b = new TempDirectory())
{
    File.WriteAllText(Path.Combine(a.TempPath, "a.txt"), "text-a");
    Directory.CreateDirectory(Path.Combine(a.TempPath, "child"));
    File.WriteAllText(Path.Combine(a.TempPath, @"child\b.txt"), "text-b");

    a.CopyTo(b.TempPath);
    Assert.IsTrue(File.Exists(Path.Combine(b.TempPath, "a.txt")));
    Assert.AreEqual("text-a", File.ReadAllText(Path.Combine(b.TempPath, "a.txt")));
    Assert.IsTrue(File.Exists(Path.Combine(b.TempPath, @"child\b.txt")));
    Assert.AreEqual("text-b", File.ReadAllText(Path.Combine(b.TempPath, @"child\b.txt")));

    File.WriteAllText(Path.Combine(a.TempPath, @"child\b.txt"), "text-b-new");
    a.CopyTo(b.TempPath, true);
    //has changed
    Assert.AreEqual("text-b-new", File.ReadAllText(Path.Combine(b.TempPath, @"child\b.txt")));
}
VB.NETCopy Code
Using a As New TempDirectory()
    Using b As New TempDirectory()
        File.WriteAllText(Path.Combine(a.TempPath, "a.txt"), "text-a")
        Directory.CreateDirectory(Path.Combine(a.TempPath, "child"))
        File.WriteAllText(Path.Combine(a.TempPath, "child\b.txt"), "text-b")

        a.CopyTo(b.TempPath)
        Assert.IsTrue(File.Exists(Path.Combine(b.TempPath, "a.txt")))
        Assert.AreEqual("text-a", File.ReadAllText(Path.Combine(b.TempPath, "a.txt")))
        Assert.IsTrue(File.Exists(Path.Combine(b.TempPath, "child\b.txt")))
        Assert.AreEqual("text-b", File.ReadAllText(Path.Combine(b.TempPath, "child\b.txt")))

        File.WriteAllText(Path.Combine(a.TempPath, "child\b.txt"), "text-b-new")
        a.CopyTo(b.TempPath, True)
        'has changed
        Assert.AreEqual("text-b-new", File.ReadAllText(Path.Combine(b.TempPath, "child\b.txt")))
    End Using
End Using

Requirements

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

See Also

Reference

TempDirectory Class
TempDirectory Members
Overload List

Used By

TestResXtoMc.TestBuildMcFromResX()
TestResXtoMcByProject.TestGenerateWin32Resource()
TestResXtoMcByProject.TestProjectResXVersionByAssembly()
TestResXtoMcByProject.TestCreateMessageAssembly()
TestResXtoMcByProject.TestProjectResXWithBadAssemblyInfo()

Source Code

Library/IO/TempDirectory.cs

Generated with Document! X 2011 by Innovasys