Skip to content

Checking if a file is already in use by another application ?

John Donman

Asked Nov 16, 2005, 9:51 AM EST1 answer
Share
LinkedInX
Hi I would like to check if a file is already open by another application before I actually save.
I have an XML being used by an application which is running. I would like to modify that XML through another application, but wanna check if the prev app is running (which uses this xml).

In simple words
if(filepath is in use)
{
   save(filepath);
}
else{
dialog(this app is being used,,,pls close other app first)
}

Note: I dont want to use exceptions. I want to prevent an exception to occur in th first place by checking in advance...any clues???

Thanks

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Mahesh Chand
    0
    I think if you open a file using File.Open method with FileAccess.ReadWrite access mode, Open method should fail and you can catch the exception at that time and instead of throwing the exception, you put your MessageBox in Catch block.
    0