aspx_professional thread: Reading a text file that is in use...
Try the OpenRead() method.
The OpenText() method will return a StreamWriter object for the specified
file.
-----Original Message-----
From: Bob [mailto:bob@l...]
Sent: Tuesday, December 11, 2001 8:36 PM
To: ASPX_Professional
Subject: [aspx_professional] Reading a text file that is in use...
I'm looking for some help ...
How can I read a text file that is in use by another process. I am trying
to read a FTP log file, so unfortunately its always "in use", but I can
open the file in notepad, so in my mind I should be able to open the file
readonly even if it is in use (Hey if notepad can do it, why can't my .net
app ?).
Does anyone know how ?
Whenever I attemp to open the file I receive the error, "The process
cannot access the file "c:\program files\ftp\ftp.log" because it is being
used by another process."
Here is the code I'm testing with...(the code works for other text files)
Dim weblog As StreamReader
Dim line As String
Dim objTable As New DataTable("logdata")
Dim objDataRow As DataRow
objTable.Columns.Add("line", System.Type.GetType("System.String"))
weblog = File.OpenText("C:\Program Files\G6 FTP Server\FTP.log")
line = weblog.ReadLine
Do While Not line Is Nothing
objDataRow = objTable.NewRow()
objDataRow("line") = line
objTable.Rows.Add(objDataRow)
objDataRow = Nothing
line = weblog.ReadLine
Loop
weblog.Close()
grdLog.DataSource = objTable.DefaultView
grdLog.DataBind()
Any help would be appreciated.
Bob Horkay
$subst('Email.Unsub').