12 Jul

Empty The Recycle Bin Using C#

This example shows how to empty the recycle bin using C#. First we will need to define the following function that will be empty the recycle bin:

        [DllImport("Shell32.dll", CharSet = CharSet.Unicode)]
        static extern uint SHEmptyRecycleBin (IntPtr hwnd, string pszRootPath, RecycleFlags dwFlags);
        public enum RecycleFlags : uint
            SHERB_NOCONFIRMATION = 0x00000001,
            SHERB_NOPROGRESSUI = 0x00000002,
            SHERB_NOSOUND = 0x00000004


uint result = SHEmptyRecycleBin(IntPtr.Zero, null, RecycleFlags.SHERB_NOCONFIRMATION);

Leave a Reply

Your email address will not be published. Required fields are marked *