You should first ask yourself, why do you write a method to check if a file is in use.
You can't use this method to avoid exceptions, because although your method returns
False just a microsecond later the file could be opened exclusivly by another program. You still would need to do any file operation inside a
Try..Catch block. So the best way would be to do just that.
Looking at your code, I would suggest to use a guard condition to save one level of indentation like so
If Not IO.File.Exists(path) Then
File.OpenWrite(string) would be enough because the only difference to
Open(FileMode, FileAccess, FileShare) would be the
FileMode value having
FileMode.OpenOrCreate and the
FileAccess value having
If you want to go the way you have posted as answer you could omit the
FileShare.None enumeration because the
Open(FileMode) method just calls the overloaded
Open(FileMode, FileAccess, FileShare) method with the same values as your call.
What I like about your code is that you apply the .NET Naming GuideLine and your using of the
Using to make sure that the stream is closed properly.
What I dislike is that you don't check wether
path is null. Proper method parameter validation for
public methods should always be done.