mtaylor314
Member
I have a website that is to read a .txt file and display it's contents in a formatted way. The problem has arised that a file may be locked and therefore it will need be readable using file.readalltext(filepath).split(vbcrlf).
I am now working on reading each file through a byte array and msdn has begun the help with that. The problem that I am having is declaring the size of the byte array. These files can range from any length from 1 word to 3 pages of information. Is there anyway of finding the length of a file in bytes without having to open it. Any help would be appreciated.
I am now working on reading each file through a byte array and msdn has begun the help with that. The problem that I am having is declaring the size of the byte array. These files can range from any length from 1 word to 3 pages of information. Is there anyway of finding the length of a file in bytes without having to open it. Any help would be appreciated.
VB.NET:
ftpfile = Session("Local") & CategoryName & ".txt"
Try
'StringArray = File.ReadAllText(ftpfile).Split(vbCrLf)
Dim oFileStream As System.IO.FileStream
oFileStream = File.OpenRead(ftpfile)
Dim obinReader As New BinaryReader(oFileStream)
Dim tmp As String = ""
'Testing another way
'=====================================================
Dim b(1024) As Byte
Dim temp As UTF8Encoding = New UTF8Encoding(True)
oFileStream.Read(b, 0, b.Length)
tmp += temp.GetString(b)
oFileStream.Close()
'======================================================
'Do Until oFileStream.Position >= oFileStream.Length - 100
' tmp += obinReader.ReadString() & Environment.NewLine
'Loop
StringArray = Split(tmp, Environment.NewLine)
...
For i As Integer = 2 To StringArray.Length - 1
If StringArray(i).Length > 1 Then
Table1.Rows(3).Cells(0).Text += StringArray(i) & Environment.NewLine
Else
Table1.Rows(3).Cells(0).Text += vbCrLf
End If
Next
Catch ex As Exception
Table1.Rows(3).Cells(0).Text += "Unable to read category file"
End Try