Empty Recycle Bin
//Namespace reference using System.Runtime.InteropServices; /// <summary> /// enum to hold the recycle /// bin flags /// </summary> enum RecycleFlags : uint { SHERB_NOCONFIRMATION = 0x00000001, SHERB_NOPROGRESSUI = 0x00000002, SHERB_NOSOUND = 0x00000004 } /// <summary> /// Import Win32 DLL for emptying the recycle bin /// </summary> /// <param name="hwnd"></param> /// <param name="pszRootPath"></param> /// <param name="dwFlags"></param> /// <returns></returns> [DllImport("Shell32.dll", CharSet = CharSet.Unicode)] static extern uint SHEmptyRecycleBin(IntPtr hwnd,string pszRootPath,RecycleFlags dwFlags); public bool EmptyRecycleBin() { try { uint result = SHEmptyRecycleBin(IntPtr.Zero, null, RecycleFlags.SHERB_NOSOUND | RecycleFlags.SHERB_NOCONFIRMATION); if (result > 0) return true; else throw new Win32Exception(Marshal.GetLastWin32Error()); } catch (Exception ex) { this._message = string.Format("Error emptying Recycle Bin: {0}", ex.Message); return false; } } Source : http://www.dreamincode.net/code/snippet1581.htm
Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.