Chilkat HOME Android™ Classic ASP C C++ C# Delphi ActiveX Delphi DLL Visual FoxPro Java MFC Objective-C Perl PHP ActiveX PHP Extension PowerShell Python Ruby SQL Server Unicode C Unicode C++ Visual Basic 6.0 VB.NET VBScript
Read Random-Access Disk File Seek Read-Only File Sharing
Download: Chilkat .NET Assemblies
VB.NET source code showing how to open a disk file for random-access in read-only / share mode. Shows how to seek from file origin, current position, or end of file.
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click ' Open an already-existing file for read-only. Allow other ' processes to open the file while we have it open. Dim fs As New FileStream("test.dat", FileMode.Open, FileAccess.Read, FileShare.Read) ' Set the file pointer to 100 bytes from the beginning. fs.Seek(100, SeekOrigin.Begin) ' Set the file pointer to the end of file. ' There's no point in doing this when we open the file read-only. ' But if you are opening the file read-write, this may be something ' of interest. fs.Seek(0, SeekOrigin.End) ' Set the file pointer to 100 bytes beyond the current position. fs.Seek(100, SeekOrigin.Current) ' Set the file pointer to 100 bytes from the beginning. fs.Seek(100, SeekOrigin.Begin) ' Read 100 bytes at this position. Dim byteArray(100) As Byte Dim numBytesRead As Integer = fs.Read(byteArray, 0, 100) fs.Close() End Sub
© 2000-2013 Chilkat Software, Inc. All Rights Reserved.