Results 1 to 3 of 3

Thread: Viewing a locked log file....

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Location
    Toowoomba, Australia
    Posts
    3

    Viewing a locked log file....

    Hey All,

    I'm currently trying to get a little VB.Net app running that has a
    FileWatcher watching a log file being generated by the PortReporter
    utility.

    The filewatcher has no problem notifying of a change in file size,
    however, i'm trying to read the changed text from the file and operate
    on it.

    The problem arises when i try to open the file, it doesn't matter what
    i do, it always returns "An unhandled exception of type
    'System.IO.IOException' occurred in mscorlib.dll".

    I have tried all manner of opening the file and always seem to get the
    error:

    EG's:
    Code:
    Dim fiLogFile As New FileInfo(txtLogFileName.Text)
    Dim fs As FileStream
    
    fsFile = fiFile.OpenRead() <-- Errors on this line
    Code:
    FileOpen(1, txtLogFileName.Text, OpenMode.Binary)
    Code:
    Dim fs As New FileStream(txtLogFileName.Text, FileMode.Open,
    FileAccess.Read)
    The kicker is that i have no problems opening and viewing the file in
    notepad and another editor called editplus.

    Anyone happen to know a way to view a locked text file in vb.net?

    Not being able to work out notepad's dirty little secret is driving me
    nuts!

    Thanks for any help you can give me

    Matt

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Viewing a locked log file....

    If your code is in the FSW's event handler, are you sure it's not just that the previous operation hasn't actually finished with the file yet? Try putting a Sleep delay before trying to open the file. If that works then you know that that is the issue and you can look for a more permanent solution to that.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Location
    Toowoomba, Australia
    Posts
    3

    Re: Viewing a locked log file....

    Thanks for the suggestion.

    I just tried isolating the file open code in it's own procedure and disabling the watcher completely (put the open code inside a button click event).

    Same result......

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