reading open files

tc490225

New member
Joined
Nov 7, 2007
Messages
4
Programming Experience
1-3
I am trying to parse logfiles that BlackBerry Enterprise Server has open, i am able to use the following code with .vbs and it works fine, however, when I try and perform the same thing in VB.NET using the System.IO i get errors saying the file is in use.. help ! I have tried everything, including using Microsoft Scripting Runtime and FSO (Which works)

.VBS
const forWriting = 2
strFileName = InputBox("Enter Filename", "Enter Filename")
strQuery = InputBox("What User", "What User")

strQuery = lcase(strquery)

Set fso = CreateObject("Scripting.FileSystemObject")
Set inFile = fso_OpenTextFile(strFileName, 1, False)
Set outFile = fso_OpenTextFile("BBLogParser" & strquery & ".txt", forWriting, true)

do while inFile.atEndOfStream = False
thisLine = lcase(inFile.readLine)

'WScript.Echo thisLine

If InStr(1, thisLine, strQuery) Then
'WScript.Echo thisLine
outFile.Write thisLine & vbNewLine
End If
Loop
wscript.echo("Complete Filtering Log " & strFileName)
 
readwrite is my friend

i was confused, imagine that.

working code..
Dim myFileStream As New System.IO.FileStream(TextBox1.Text, _
FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite)

Dim myReader As New System.IO.StreamReader(myFileStream)

Dim sFileContents As String = myReader.ReadToEnd()

RichTextBox1.Text = sFileContents

myReader.Close()
myFileStream.Close()
MsgBox("Complete")
 
Back
Top