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.
CharSet = CharSet.Unicode, Pack = 1)]
public struct SHQUERYRBINFO
SHQueryRecycleBin() method of shell32 dll to query file size and file number
/// in recycle bin.
CharSet = CharSet.Unicode)]
public static extern 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.
= 0x00000004 //No sound whent while emptying recycle bin.
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
bb_Query.cbSize = Marshal.SizeOf(bb_Query.GetType());
SHQueryRecycleBin(null, ref bb_Query);
" + bb_Query.cbSize);
" + bb_Query.i64Size);
//Call i64Size member of structure which will
return size of recycle bin.
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.