Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 742
netcat Avatar asked Nov 26 '11 09:11

netcat


1 Answers

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.

like image 52
schglurps Avatar answered Oct 02 '22 00:10

schglurps