In this article I will describe that how to work with recycle bin such as retrieving number of files in recycle bin, calculating size of files in recycle bin and deleting content of recycle bin. First of all I would like to tell you that I had already solve it by adding reference of Shell32 dll but that is not great solution because when I create setup then due to Shell32 dll size of application become more than 6 mb which is not good. So finally lot of googling and forums search I got an efficient solution which worked for me. Here I will give you sample code which is useful for you.
Sample code for recycle bin
/// Create an structure which will store recycle query information.
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)]
public struct SHQUERYRBINFO
public Int32 cbSize;
public UInt64 i64Size;
public UInt64 i64NumItems;
/// Call SHQueryRecycleBin() method of shell32 dll to query file size and file number
/// in recycle bin.
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
public static extern int SHQueryRecycleBin(
ref SHQUERYRBINFO pSHQueryRBInfo
enum RecycleFlags : int
SHERB_NOCONFIRMATION = 0x00000001, //No confirmation dialog will open while emptying recycle bin.
SHERB_NOPROGRESSUI = 0x00000001, //No progress tracking window appears while emptying recycle bin.
SHERB_NOSOUND = 0x00000004 //No sound whent while emptying recycle bin.
/// Call SHEmptyRecycleBin() method of shell32 dll to empty recycle bin.
static extern int SHEmptyRecycleBin(IntPtr hwnd, string psrRootPath, RecycleFlags dwFlags);
/// This method will empty recycle bin without prompting confirmation message.
public static void emptyRecycleBin()
SHEmptyRecycleBin(IntPtr.Zero, null, RecycleFlags.SHERB_NOCONFIRMATION);
static void Main(string args)
SHQUERYRBINFO bb_Query = new SHQUERYRBINFO();
bb_Query.cbSize = Marshal.SizeOf(bb_Query.GetType());
SHQueryRecycleBin(null, ref bb_Query);
Console.WriteLine("CB Size : " + bb_Query.cbSize);
Console.WriteLine("File Size : " + bb_Query.i64Size); //Call i64Size member of structure which will return size of recycle bin.
Console.WriteLine("Number of items : " + bb_Query.i64NumItems); //Call i64NumItems member of structure which will return file number in recycle bin.
emptyRecycleBin(); //call empty recycle bin which will empty ur recycle bin.