I need to delete a file. Sometimes a file may be locked, in which case I would like to unlock it and delete it anyway.
I have found two possibilities in research so far.
System.IO.FileStream.Unlock
and
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool UnlockFile(IntPtr handle, int offsetLow, int offsetHi);`
Will either of these two methods work? If so, could you please provide a sample as I have not received any of them for work. Or is there any other better way?
source
share