none
Newbie File IO question RRS feed

  • Question

  • Hi Everyone,
       I'm new to C# (I'm a VB developer). I was told to move to the dark side - so here I am.  :-)

    I'm doing some file IO work that involves reading ftp log files. These things are continually being opened, written and closed.

    I've written a class that goes ahead and checks if a file, directory exists and returns the last modified date/time.

    What I would like to be able to do is determine if the file is currently open (opened by another process somewhere).

    Is there a way of doing this in C#?

    thanks in advance,
    Ed.
    Thursday, July 28, 2005 12:37 PM

Answers

  • Not really - unless you write a file system driver (I think).

    However, if the other process has opened the file in exclusive mode, your call to open the file will fail.  That way you can know if the file is locked.

    BTW, welcome to the bright part of the dark side.
    Thursday, July 28, 2005 5:35 PM
    Moderator

All replies

  • Not really - unless you write a file system driver (I think).

    However, if the other process has opened the file in exclusive mode, your call to open the file will fail.  That way you can know if the file is locked.

    BTW, welcome to the bright part of the dark side.
    Thursday, July 28, 2005 5:35 PM
    Moderator
  • Hi,
       thanks for that.


    I've come up with a solution in the mean time.

    If I write ablock of code that loops trying to do a file open (for write) and just keeps looping until it gets the file it's fine.

    Obviously the next line of code is a close so that the file is only held by my app for milli seconds.

    thanks,
    Ed.
    Tuesday, August 16, 2005 9:27 AM