|
-
Feb 15th, 2003, 12:27 AM
#1
Thread Starter
New Member
how do I open a log file thats in use (read is only needed)
Hello, I need to open a log file, but the files always in use..
no matter what i do I keep getting
"An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
Additional information: The process cannot access the file "... .log" because it is being used by another process."
I can open the file in notepad and wordpad, why cant I / how do I open it in my code?
this is my code now.
[code=vb]
If IO.File.Exists(LogPath) = True Then
Dim st As IO.FileStream = IO.File.Open(LogPath, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
Dim sr As New IO.StreamReader(st)
Dim a() As String = Split(sr.ReadToEnd, vbCrLf)
[/code]
~~~~~~~~~~~~~~~~~~~~
PeAcE
DrDave
-
Feb 15th, 2003, 10:01 AM
#2
Member
If you need to read it only, you can copy it to a different file first and then open.
PS you CAN copy the file that is in use
-
Feb 15th, 2003, 10:26 AM
#3
Sleep mode
try this way :
VB Code:
Dim read As IO.BinaryReader
read = New IO.BinaryReader(IO.File.OpenRead(path))
Dim str As String = read.ReadString
read.Close()
read = Nothing
-
Feb 15th, 2003, 10:29 AM
#4
-
Feb 15th, 2003, 12:47 PM
#5
Thread Starter
New Member
Ya copying it works, BUT there has to be a way to read it?
My log files are a little big so copying it everytime it changes is a big job..
ANY IDEAS??
~~~~~~~~~~~~~~~~~~~~
PeAcE
DrDave
-
May 31st, 2004, 04:49 PM
#6
yay gay
I'm really needing to open a file that is currently in use too and don't know how. Any ideias?
\m/  \m/
-
May 31st, 2004, 04:57 PM
#7
Frenzied Member
Howcome the file is in use?? Look there first... I sometimes forget to close my file pointers leaving the file/dbconnection/usbpipe/whatever open...
It's not a good programming mentality to leave files open for along period of time.... perform
open->write->close even if you write to the file frequently...
if you get this exception, catch it and retry... normally it doesn't take many ms to write some lines to a textfile...
kind regards
Henrik
-
Jun 6th, 2004, 11:53 AM
#8
Thread Starter
New Member
The file is an IIS Log File...
Its not my file, but now you can see why its open all the time right.
You can right click > open with notepad and the file will open... but if i use wordpad it wont. There has to be a way to open that file read-only while its in use???????
~~~~~~~~~~~~~~~~~~~~
PeAcE
DrDave
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|