CSharpTest.Net
CreateNew(String,Int32) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace > FragmentedFile Class > CreateNew Method : CreateNew(String,Int32) Method

filename
blockSize

Glossary Item Box

Creates a new file (or truncates an existing one) that stores multiple smaller files

Syntax

Visual Basic (Declaration) 
Public Overloads Shared Function CreateNew( _
   ByVal filename As String, _
   ByVal blockSize As Integer _
) As FragmentedFile
C# 
public static FragmentedFile CreateNew( 
   string filename,
   int blockSize
)

Parameters

filename
blockSize

Example

Library/Library.Test/TestFragmentedFile.cs

C#Copy Code
using (TempFile file = new TempFile())
{
    Guid guid = Guid.NewGuid();
    long id;

    using (FragmentedFile ff = FragmentedFile.CreateNew(file.TempPath, 512))
    {
        using (Stream io = ff.Create(out id))
            PrimitiveSerializer.Guid.WriteTo(guid, io);
        Assert.AreEqual(id, ff.FirstIdentity);
    }
    using (FragmentedFile ff = new FragmentedFile(file.TempPath, 512))
    {
        Assert.AreEqual(id, ff.FirstIdentity);
        using (Stream io = ff.Open(id, FileAccess.Read))
            Assert.AreEqual(guid, PrimitiveSerializer.Guid.ReadFrom(io));
    }
    using (FragmentedFile ff = new FragmentedFile(file.TempPath, 512, 10, 10, FileAccess.Read, FileShare.None, FileOptions.None))
    {
        Assert.AreEqual(id, ff.FirstIdentity);
        using (Stream io = ff.Open(id, FileAccess.Read))
            Assert.AreEqual(guid, PrimitiveSerializer.Guid.ReadFrom(io));

        AssertThrows<InvalidOperationException>(delegate() { ff.Open(id, FileAccess.Write).Dispose(); });
    }
}
VB.NETCopy Code
Using file As New TempFile()
    Dim guid As Guid = Guid.NewGuid()
    Dim id As Long

    Using ff As FragmentedFile = FragmentedFile.CreateNew(file.TempPath, 512)
        Using io As Stream = ff.Create(id)
            PrimitiveSerializer.Guid.WriteTo(guid, io)
        End Using
        Assert.AreEqual(id, ff.FirstIdentity)
    End Using
    Using ff As New FragmentedFile(file.TempPath, 512)
        Assert.AreEqual(id, ff.FirstIdentity)
        Using io As Stream = ff.Open(id, FileAccess.Read)
            Assert.AreEqual(guid, PrimitiveSerializer.Guid.ReadFrom(io))
        End Using
    End Using
    Using ff As New FragmentedFile(file.TempPath, 512, 10, 10, FileAccess.Read, FileShare.None, _
        FileOptions.None)
        Assert.AreEqual(id, ff.FirstIdentity)
        Using io As Stream = ff.Open(id, FileAccess.Read)
            Assert.AreEqual(guid, PrimitiveSerializer.Guid.ReadFrom(io))
        End Using

        AssertThrows(Of InvalidOperationException)(Function() Do
            ff.Open(id, FileAccess.Write).Dispose()
        End Function)
    End Using
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