Empty the Recycle Bin

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
C# Code Snippets

C# Source Code Bank

See also …
edit

This C# code snippet empties the Recycle Bin. Windows will display a confirmation dialog box.

using System.Runtime.InteropServices;
...
enum RecycleFlags : uint
{
   SHERB_NOCONFIRMATION = 0x00000001,
   SHERB_NOPROGRESSUI   = 0x00000002,
   SHERB_NOSOUND        = 0x00000004
}
 
[DllImport("Shell32.dll", CharSet = CharSet.Unicode)]
static extern uint SHEmptyRecycleBin 
	(IntPtr hwnd, 
	string pszRootPath,
	RecycleFlags dwFlags);
	
public static void Main()
{
    uint result = SHEmptyRecycleBin (IntPtr.Zero, null, 0);
    Console.WriteLine ("Result: {0}", result);
}

Personal tools