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

filename

Glossary Item Box

Manage the provided file path

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal filename As String _
)
C# 
public TempFile( 
   string filename
)

Parameters

filename

Example

Library/Library.Test/TestTempFiles.cs

C#Copy Code
string path = Path.GetTempFileName();
Assert.IsTrue(File.Exists(path));
File.WriteAllText(path, "Test");

TempFile filea = TempFile.Attach(path);
Assert.AreEqual(path, filea.TempPath);
Assert.AreEqual("Test", File.ReadAllText(filea.TempPath));

filea.Dispose();
Assert.IsFalse(File.Exists(path));

using (TempFile filec = new TempFile(path))
    Assert.IsFalse(File.Exists(path));
VB.NETCopy Code
Dim path As String = Path.GetTempFileName()
Assert.IsTrue(File.Exists(path))
File.WriteAllText(path, "Test")

Dim filea As TempFile = TempFile.Attach(path)
Assert.AreEqual(path, filea.TempPath)
Assert.AreEqual("Test", File.ReadAllText(filea.TempPath))

filea.Dispose()
Assert.IsFalse(File.Exists(path))

Using filec As New TempFile(path)
    Assert.IsFalse(File.Exists(path))
End Using

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys