Does File.Copy prevent another application from being written to a file?

I want to copy some text files written by another application, but I do not want to do anything to prevent another application. from writing to these files.

I am using File.Copy , from System.IO namespace , C # ,. Net Framework 2.0.

I checked the MSDN documentation, but nothing specifically stated about the method that uses File.Copy . Is it a wrapper for an unmanaged API call?

Does File.Copy block or block the copied file in any way?

Thanks in advance for any information on this.

+7
source share
2 answers

You can use .NET Reflector (or another decompilation tool) to look at the internal structure of the method.

In fact, you can see that System.IO File.Copy uses the Microsoft.Win32.Win32Native library to copy files. Microsoft.Win32.Win32Native is a CLR shell for all Win32 operations.

+1
source

If another application creates its files by specifying FileShare.None, you will get a UnauthorizedAccessException. Therefore, I assume that you just need to handle this particular exception in your application.

+2
source

All Articles