FileInfo CopyTo method throwing an IOException (.net)
<p>The CopyTo method of FileInfo class throws an IOException </p>

<p>The process cannot access the file 'C:\Data\Test.XML' because it is being used by another process.</p>

<p>Any ideas on why this should happen? I understand that copying a file just requires read access. So ideally even if the file is write protected or is opened by some other program the CopyTo should have no problem executing.</p>

<pre><code>FileInfo copyFile = null;

//currentFile.FileInformation is of type FileInfo which is referring to the file for which a copy is being created. In this case it is C:\Data\Test.XML
System.IO.FileInfo file = new FileInfo(currentFile.FileInformation.FullName);

// Constructing name for the temporary copy of Test.XML
string newName = "Temp Copy of " + currentFile.FileInformation.Name;

//This is where I get the exception. The CopyTo fails...
copyFile = file.CopyTo(System.IO.Path.Combine(currentFile.FileInformation.DirectoryName, newName), true);

fs = System.IO.File.Open(copyFile.FullName, FileMode.Open);
</code></pre>

<p><strong>Also some important points to note :</strong></p>

<ul>
<li>I have write access to the folder to which I am trying to copy. This is happening with only certain files.</li>
<li>The file for which I am trying to create a copy of is not Read-only.</li>
</ul>

<p>Please let me know if I can provide you with any more details</p>

<p>Thanks in advance</p>
