Results 1 to 8 of 8

Thread: how do I open a log file thats in use (read is only needed)

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Location
    Surrey, British Columbia, Canada
    Posts
    4

    Question 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

  2. #2
    Member
    Join Date
    Dec 2002
    Location
    NY, USA
    Posts
    52
    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
    Iouri Boutchkine

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    try this way :
    VB Code:
    1. Dim read As IO.BinaryReader
    2. read = New IO.BinaryReader(IO.File.OpenRead(path))
    3. Dim str As String = read.ReadString
    4. read.Close()
    5. read = Nothing

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    oh this won't solve it. I believe you are trying to read it while it is in use . .Well , try Iouri's way seems logical

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Location
    Surrey, British Columbia, Canada
    Posts
    4
    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

  6. #6
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    I'm really needing to open a file that is currently in use too and don't know how. Any ideias?
    \m/\m/

  7. #7
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    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

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Location
    Surrey, British Columbia, Canada
    Posts
    4
    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
  •  



Click Here to Expand Forum to Full Width