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

data

Glossary Item Box

Writes all bytes to the file

Syntax

Visual Basic (Declaration) 
Public Sub WriteAllBytes( _
   ByVal data() As Byte _
) 
C# 
public void WriteAllBytes( 
   byte[] data
)

Parameters

data

Example

Library/Library.Test/TestTempFiles.cs

C#Copy Code
string test = "Hello World!\u1255";
TempFile file = new TempFile();
File.WriteAllBytes(file.TempPath, Encoding.UTF8.GetBytes(test));

Assert.AreEqual(Encoding.UTF8.GetBytes(test), file.ReadAllBytes());
Assert.AreEqual(test, file.ReadAllText());

file.Delete();
Assert.IsFalse(File.Exists(file.TempPath));
Assert.IsFalse(file.Exists);
file.WriteAllBytes(Encoding.UTF8.GetBytes(test));
Assert.AreEqual(test, file.ReadAllText());

file.Delete();
Assert.IsFalse(File.Exists(file.TempPath));
Assert.IsFalse(file.Exists);
file.WriteAllText(test);
Assert.AreEqual(test, file.ReadAllText());
VB.NETCopy Code
Dim test As String = "Hello World!ቕ"
Dim file As New TempFile()
File.WriteAllBytes(file.TempPath, Encoding.UTF8.GetBytes(test))

Assert.AreEqual(Encoding.UTF8.GetBytes(test), file.ReadAllBytes())
Assert.AreEqual(test, file.ReadAllText())

file.Delete()
Assert.IsFalse(File.Exists(file.TempPath))
Assert.IsFalse(file.Exists)
file.WriteAllBytes(Encoding.UTF8.GetBytes(test))
Assert.AreEqual(test, file.ReadAllText())

file.Delete()
Assert.IsFalse(File.Exists(file.TempPath))
Assert.IsFalse(file.Exists)
file.WriteAllText(test)
Assert.AreEqual(test, file.ReadAllText())

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.TestLogCorruption()

Source Code

Library/IO/TempFile.cs

Generated with Document! X 2011 by Innovasys