public static void DeleteFile(string filePath) { filePath = CheckAddLongPathPrefix(filePath); if (!PInvokeHelper.DeleteFile(filePath)) { // http://msdn.microsoft.com/en-us/library/ms681382(VS.85).aspx. var lastWin32Error = Marshal.GetLastWin32Error(); if (lastWin32Error != PInvokeHelper.ERROR_NO_MORE_FILES && lastWin32Error != PInvokeHelper.ERROR_FILE_NOT_FOUND) { // Sometimes it returns "ERROR_SUCCESS" and stil deletes the file. var t = lastWin32Error != PInvokeHelper.ERROR_SUCCESS || FileExists(filePath); // -- if (t) { throw new Win32Exception( lastWin32Error, string.Format( Resources.ErrorDeletingFile, lastWin32Error, filePath, CheckAddDotEnd(new Win32Exception(lastWin32Error).Message))); } } } }