/// <summary> /// Send file to recycle bin /// </summary> /// <param name="path">Location of directory or file to recycle</param> /// <param name="flags">FileOperationFlags to add in addition to FOF_ALLOWUNDO</param> public static bool Send(string path, NativeMethods.FileOperationFlags flags) { try { if (NativeMethods.IsWOW64Process()) { NativeMethods.SHFILEOPSTRUCT_x64 fs = new NativeMethods.SHFILEOPSTRUCT_x64(); fs.wFunc = NativeMethods.FileOperationType.FO_DELETE; // important to double-terminate the string. fs.pFrom = path + '\0' + '\0'; fs.fFlags = NativeMethods.FileOperationFlags.FOF_ALLOWUNDO | flags; NativeMethods.SHFileOperation_x64(ref fs); } else { NativeMethods.SHFILEOPSTRUCT_x86 fs = new NativeMethods.SHFILEOPSTRUCT_x86(); fs.wFunc = NativeMethods.FileOperationType.FO_DELETE; // important to double-terminate the string. fs.pFrom = path + '\0' + '\0'; fs.fFlags = NativeMethods.FileOperationFlags.FOF_ALLOWUNDO | flags; NativeMethods.SHFileOperation_x86(ref fs); } return true; } catch { return false; } }
/// <summary> /// Send file to recycle bin /// </summary> /// <param name="path">Location of directory or file to recycle</param> /// <param name="flags">FileOperationFlags to add in addition to FOF_ALLOWUNDO</param> private static bool Send(string path, NativeMethods.FileOperationFlags flags) { try { if (NativeMethods.IsWOW64Process()) { NativeMethods.SHFILEOPSTRUCT_x64 fs = new NativeMethods.SHFILEOPSTRUCT_x64(); fs.wFunc = NativeMethods.FileOperationType.FO_DELETE; // important to double-terminate the string. fs.pFrom = path + '\0' + '\0'; fs.fFlags = NativeMethods.FileOperationFlags.FOF_ALLOWUNDO | flags; NativeMethods.SHFileOperation_x64(ref fs); } else { NativeMethods.SHFILEOPSTRUCT_x86 fs = new NativeMethods.SHFILEOPSTRUCT_x86(); fs.wFunc = NativeMethods.FileOperationType.FO_DELETE; // important to double-terminate the string. fs.pFrom = path + '\0' + '\0'; fs.fFlags = NativeMethods.FileOperationFlags.FOF_ALLOWUNDO | flags; NativeMethods.SHFileOperation_x86(ref fs); } return(true); } catch { return(false); } }