Results 1 to 12 of 12

Thread: I need to read a Text file thats in use.

  1. #1

    Thread Starter
    Addicted Member DigitalMyth's Avatar
    Join Date
    Nov 2002
    Location
    England..
    Posts
    169

    Lightbulb I need to read a Text file thats in use.

    The process can not access the file 'C:\Program Files\EA GAMES\MOHAA\mainta\qconsole.log' because it is being used by another process.
    I need to read this file that is in use. How do i do it?

  2. #2
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251
    What are you currently using to read the file?

    I have had much success with the System.IO.Streamreader in situations like this.
    ~Ryan





    Have I helped you? Please Rate my posts.

  3. #3

    Thread Starter
    Addicted Member DigitalMyth's Avatar
    Join Date
    Nov 2002
    Location
    England..
    Posts
    169
    File: Status.aspx?session=3000

    VB Code:
    1. <%    
    2.  
    3.         Dim path as String = "C:\Program Files\EA GAMES\MOHAA\mainta\qconsole.log"
    4.    
    5.     Dim fs as filestream
    6.  
    7.         fs = File.OpenRead(path)
    8.         Dim b(1024) As Byte
    9.         Dim temp As UTF8Encoding = New UTF8Encoding(True)
    10.  
    11.         Do While fs.Read(b, 0, b.Length) > 0
    12.             response.write(temp.GetString(b))
    13.         Loop
    14.         fs.Close()
    15.  
    16.  
    17.  %>

  4. #4
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251
    Try:

    Code:
    Dim sr As StreamReader
    Dim strText As String
    Dim path as String = "C:\Program Files\EA GAMES\MOHAA\mainta\qconsole.log"
    
    Try
         sr = New StreamReader(path)
         strText = sr.ReadToEnd()
         sr.Close()
    Catch ex As Exception
         Throw
    End Try
    ~Ryan





    Have I helped you? Please Rate my posts.

  5. #5

    Thread Starter
    Addicted Member DigitalMyth's Avatar
    Join Date
    Nov 2002
    Location
    England..
    Posts
    169
    same error on throw.

    i don't understand this because i made a simple VB program to do the same thing can that has no problems.

  6. #6
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251
    Have you given the ASPNET client and IUSR account read access to file? It could be a hidden permissions issue.
    ~Ryan





    Have I helped you? Please Rate my posts.

  7. #7
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Try this

    VB Code:
    1. FileOpen(intFileNumber, "C:\Program Files\EA GAMES\MOHAA\mainta\qconsole.log", OpenMode.Input, OpenAccess.Read, OpenShare.Shared)
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  8. #8

    Thread Starter
    Addicted Member DigitalMyth's Avatar
    Join Date
    Nov 2002
    Location
    England..
    Posts
    169
    Yes the permissions are correct.

    And what class is Openfile under i can't find it???

  9. #9
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Sorry you need to ensure you're importing from the System.IO namespace
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  10. #10

    Thread Starter
    Addicted Member DigitalMyth's Avatar
    Join Date
    Nov 2002
    Location
    England..
    Posts
    169
    BC30456: 'Openfile' is not a member of 'IO'.
    Last edited by DigitalMyth; Sep 9th, 2004 at 11:12 AM.

  11. #11
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251
    Originally posted by DigitalMyth
    BC30456: 'Openfile' is not a member of 'IO'.
    Its FileOpen not OpenFile, so I imagine you are having a syntax error

    Jamie's code worked fine for me, I didn't need to import the system.io class for make it work
    ~Ryan





    Have I helped you? Please Rate my posts.

  12. #12

    Thread Starter
    Addicted Member DigitalMyth's Avatar
    Join Date
    Nov 2002
    Location
    England..
    Posts
    169
    Oooopppsss. Sorry, I didn't see ya mistake.

    Thanks it working great now.

    DigitalMyth

    VB Code:
    1. <%    
    2.  
    3.  
    4.         FileOpen(1, "C:\Program Files\EA GAMES\MOHAA\mainta\qconsole.log", OpenMode.Input, OpenAccess.Read, OpenShare.Shared)
    5.    
    6.    
    7.     Do While Not EOF(1)  
    8.  
    9.            Dim TextLine as string = LineInput(1)
    10.  
    11.            Response.write(Textline)
    12.            Response.Write("<br>")
    13.     Loop
    14.  
    15.  
    16.     Fileclose(1)
    17.  
    18.  %>

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