Results 1 to 6 of 6

Thread: Cannot access the file because it's being used by another process?

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jan 2016
    Posts
    9

    Cannot access the file because it's being used by another process?

    Hello,
    So lately I've been working on a tool, and a line of the whole code is:
    Code:
    Label1.Text = (IO.File.ReadAllLines("Test.txt").Count(Function(l) l.Contains("smthing")))
    The code is just reading I think, not replacing or editing, why is it telling me that I still can't access it?
    However this line is the necessary thing in the whole code and in the same time I want to keep the process using the file running.
    Or is there a way to bypass this?
    Thanks in advance.

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,807

    Re: Cannot access the file because it's being used by another process?

    Hi,
    Unless that other process that has your file open is a program written by you I don't see any other way to let your program access it than to close that other process.
    What are you trying to accomplish and what is that other process any way?

  3. #3

    Thread Starter
    Registered User
    Join Date
    Jan 2016
    Posts
    9

    Re: Cannot access the file because it's being used by another process?

    Quote Originally Posted by Peter Swinkels View Post
    Hi,
    Unless that other process that has your file open is a program written by you I don't see any other way to let your program access it than to close that other process.
    What are you trying to accomplish and what is that other process any way?
    The thing I'm trying to do is to make my program able to access the file and get the number of lines that have "smthing" and in the same time allow the other program to access and edit it, because I need the edits of it to update the lines number in my program.

  4. #4
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,429

    Re: Cannot access the file because it's being used by another process?

    Hi,

    Maybe you could add a ListBox, (Unsorted) then fill it with the text from your file, close the file, then use the text in the ListBox for your application.
    Looks as though you're also counting the number of lines, a TextBox automatically counts it's contents. Beware though, the count maybe (say) 10, but that's addressed as 0 to 9.

    Or... Open a new text file, Give it an unused suffix (.ngo for example, in stead of .txt) copy all of the relevant file to that (FileCopy would be an easy way)
    then use that to read from.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  5. #5

    Thread Starter
    Registered User
    Join Date
    Jan 2016
    Posts
    9

    Re: Cannot access the file because it's being used by another process?

    Quote Originally Posted by Poppa Mintin View Post
    Hi,

    Maybe you could add a ListBox, (Unsorted) then fill it with the text from your file, close the file, then use the text in the ListBox for your application.
    Looks as though you're also counting the number of lines, a TextBox automatically counts it's contents. Beware though, the count maybe (say) 10, but that's addressed as 0 to 9.

    Or... Open a new text file, Give it an unused suffix (.ngo for example, in stead of .txt) copy all of the relevant file to that (FileCopy would be an easy way)
    then use that to read from.

    Poppa.
    The program updates/edits the file every 15-20 seconds and I want to get the full text.

  6. #6

    Thread Starter
    Registered User
    Join Date
    Jan 2016
    Posts
    9

    Re: Cannot access the file because it's being used by another process?

    I tried suspending the process using the file while I'm getting the lines count but this doesn't work either.

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