Does File.Copy prevent another app from writing to the file?

I want to copy some text files, that are written by another app, but I don't want to do anything to prevent the other app. from writing to these files.

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

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

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

Thanks in advance for any info about this.


You can use .Net Reflector (or other decompile tool) to look at internal structure of the method.

Actually you can see that System.IO File.Copy uses Microsoft.Win32.Win32Native library for coping files. Microsoft.Win32.Win32Native it is CLR wrapper for all Win32 native operations.


If the other app creates its files by specifying FileShare.None, you will receive an UnauthorizedAccessException. So I imagine that you just have to process this specific exception in your app.

链接地址: http://www.djcxy.com/p/10058.html

上一篇: 带控制按钮的jQuery UI滑块?

下一篇: File.Copy是否阻止另一个应用程序写入文件?