/// <summary> /// Move file to recycle bin, don't display any dialogs or errors. /// </summary> /// <param name="filePath">Path of the file that should be moved to recycle bin</param> public static bool MoveFileToRecycleBin(string filePath) { try { FileOperationFlags operationFlags = FileOperationFlags.AllowUndo | FileOperationFlags.NoProgressDialogBox | FileOperationFlags.NoConfirmation | FileOperationFlags.NoError; var fileOperationData = new FileOperationStruct { ActionToPerform = 3, SourcePath = filePath, OperationFlags = operationFlags }; SHFileOperation(ref fileOperationData); return(true); } catch (Exception) { return(false); } }
private static extern int SHFileOperation(ref FileOperationStruct fileOperationStruct);