PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
need help opening a text file in use by another program-VBForums
Results 1 to 6 of 6

Thread: need help opening a text file in use by another program

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    3

    need help opening a text file in use by another program

    I need to be able to view another programs chatlog while it is running. this is the existing code. right now for testing it just reads the first line of file. this reads the file just fine as long as the other program isnt running but if it is running i get an error stating that the file is in use by another process. I'm using vb 2010 express.
    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim fileReader As System.IO.StreamReader
    3.         fileReader = _
    4.         My.Computer.FileSystem.OpenTextFileReader("C:\chatlog")
    5.         Dim stringReader As String
    6.         stringReader = fileReader.ReadLine()
    7.         textbox1.text = stringReader
    Last edited by Hack; May 22nd, 2012 at 12:56 PM. Reason: Added Highlight Tags

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: need help opening a text file in use by another program

    Why are you trying to read someone else's chat file?

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    3

    Re: need help opening a text file in use by another program

    im workin on a 3rd party addon for a game. it does not break any rules or anything like that. it needs to see the chatlogs to get info.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: need help opening a text file in use by another program

    Very well...then I will move your thread to the appropriate VBForums section, which is VB.NET

  5. #5
    New Member
    Join Date
    Apr 2012
    Location
    Florida, USA
    Posts
    5

    Re: need help opening a text file in use by another program

    This opens the filestream as read only and passes the filestream to a streamreader.

    Code:
    Dim chatFileStream As New FileStream("c:\Chat.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
    Dim chatFileReader As New StreamReader(chatFileStream)

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    3

    Re: need help opening a text file in use by another program

    that did it, thank you for the response. it has been stumping me for two days

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width