I have the following C# code:
static void Main(string[] args)
{
FileStream fileStream = null;
try
{
// read from file or write to file
fileStream = new FileStream(@"D:\FileLock.txt", FileMode.Open, FileAccess.Read, FileShare.None);
}
catch
{
}
finally
{
fileStream.Close();
}
}
and I'm trying to copy the file "D:\FileLock.txt" to another location using the following C (WinAPI) code:
CopyFile(_T("D:\\FileLock.txt"), _T("D:\\temp\\FileLock.txt"),FALSE);
But I get ERROR_SHARING_VIOLATION (as expected).
Is there anyway I can bypass this? (i.e. copy the file under these conditions) --without modifying the C# code