Opens the file with the identity previously obtained by Create() using the access provided; however, Read+Write is not supported, use either Read or Write but not both.
Syntax
Parameters
- identity
- access
Exceptions
Exception | Description |
System.ArgumentOutOfRangeException | The exception that is thrown when the value of an argument is outside the allowable range of values as defined by the invoked method. |
Example
Library/Library.Test/TestFragmentedFile.cs
C# | Copy Code |
---|
using (SharedMemoryStream shared = new SharedMemoryStream())
using (FragmentedFile ff = FragmentedFile.CreateNew(shared, 512, 100, 2))
{
long id = ff.Create();
using (Stream write = ff.Open(id, FileAccess.Write))
{
Assert.IsFalse(write.CanRead);
Assert.IsTrue(write.CanWrite);
Assert.IsFalse(write.CanSeek);
PrimitiveSerializer.Int64.WriteTo(id, write);
write.Flush();//no-op
AssertThrows<NotSupportedException>(delegate() { write.Position = 0; });
AssertThrows<NotSupportedException>(delegate() { GC.KeepAlive(write.Position); });
AssertThrows<NotSupportedException>(delegate() { GC.KeepAlive(write.Length); });
AssertThrows<NotSupportedException>(delegate() { write.SetLength(1); });
AssertThrows<NotSupportedException>(delegate() { write.Seek(1, SeekOrigin.Begin); });
AssertThrows<NotSupportedException>(delegate() { write.ReadByte(); });
}
} |
VB.NET | Copy Code |
---|
Using [shared] As New SharedMemoryStream()
Using ff As FragmentedFile = FragmentedFile.CreateNew([shared], 512, 100, 2)
Dim id As Long = ff.Create()
Using write As Stream = ff.Open(id, FileAccess.Write)
Assert.IsFalse(write.CanRead)
Assert.IsTrue(write.CanWrite)
Assert.IsFalse(write.CanSeek)
PrimitiveSerializer.Int64.WriteTo(id, write)
write.Flush()
'no-op
AssertThrows(Of NotSupportedException)(Function() Do
write.Position = 0
End Function)
AssertThrows(Of NotSupportedException)(Function() Do
GC.KeepAlive(write.Position)
End Function)
AssertThrows(Of NotSupportedException)(Function() Do
GC.KeepAlive(write.Length)
End Function)
AssertThrows(Of NotSupportedException)(Function() Do
write.SetLength(1)
End Function)
AssertThrows(Of NotSupportedException)(Function() Do
write.Seek(1, SeekOrigin.Begin)
End Function)
AssertThrows(Of NotSupportedException)(Function() Do
write.ReadByte()
End Function)
End Using
End Using
End Using |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also