CSharpTest.Net
Attach Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace > TempFile Class : Attach Method

existingPath

Glossary Item Box

Attaches a new instances of a TempFile to the provided file path

Syntax

Visual Basic (Declaration) 
Public Shared Function Attach( _
   ByVal existingPath As String _
) As TempFile
C# 
public static TempFile Attach( 
   string existingPath
)

Parameters

existingPath

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

Reference

TempFile Class
TempFile Members

Used By

TestTransactionLog.TestBenchmarkWriteSpeed()
ThreadedBTreeTest.TestAbortWritersAndRecover()
TestResXtoMcByProject.TestGenerateWin32Resource()
TestResXtoMcByProject.TestProjectResXVersionByAssembly()
TestResXtoMcByProject.TestCreateMessageAssembly()
TestResXtoMcByProject.TestProjectResXWithBadAssemblyInfo()
Boolean SecureTransfer.Client.Download(String,String)

Source Code

Library/IO/TempFile.cs

Generated with Document! X 2011 by Innovasys