I need to delete a file. Occasionally, the file may be locked, in this case I'd like to unlock it and delete it anyway.
I've come across two possibilities in the research so far.
System.IO.FileStream.Unlock
and
//unlock file
[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 gotten either of these to work. Or, is there another better way?