---
title: "Recycle bin in c#."  
description: "Hi......  In this blog I will tell you that how to work with recycle bin such as how to get file size, delete files of recycle bin and retrive number"  
author: "Anonymous User"  
published: 2011-05-25  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/188/recycle-bin-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Recycle bin in c#.

In this [article](https://www.mindstick.com/articles/95867/are-you-looking-for-500-credit-score-mortgage-lenders-houston-continue-reading-this-article) I will [describe](https://www.mindstick.com/interview/12752/what-is-ddms-describe-some-of-its-capabilities) that how to work with [recycle bin](https://www.mindstick.com/articles/1716/change-recycle-bin-settings-in-windows-os) such as retrieving number of files in recycle bin, calculating size of files in recycle bin and deleting [content](https://www.mindstick.com/articles/13019/get-the-best-content-marketing-pricing-packages-for-your-brand) of recycle bin. First of all I would like to tell you that I had [already](https://yourviews.mindstick.com/view/88453/the-hidden-ways-ai-is-already-controlling-your-daily-life) solve it by adding [reference](https://www.mindstick.com/forum/774/reference-what-does-this-error-mean-in-php) of Shell32 dll but that is not great solution because when I create setup then due to Shell32 dll size of [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) become more than 6 mb which is not good. So finally lot of googling and forums [search](https://www.mindstick.com/blog/301883/why-you-shouldn-t-trust-ai-search-engines) I got an [efficient](https://www.mindstick.com/articles/33637/three-tips-for-an-energy-efficient-home-for-2019) solution which worked for me. Here I will give you sample code which is [useful](https://www.mindstick.com/articles/12694/how-dolomite-mineral-is-useful-in-human-life) for you.

##### Sample code for recycle bin

```
using System;using System.IO;using System.Runtime.InteropServices;namespace ConsoleApplication5{    class Program    {        /// <summary>        /// Create an structure which will store recycle query information.        /// </summary>        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)]        public struct SHQUERYRBINFO        {            public Int32 cbSize;            public UInt64 i64Size;            public UInt64 i64NumItems;        }        /// <summary>        /// Call SHQueryRecycleBin() method of shell32 dll to query file size and file number        /// in recycle bin.        /// </summary>        [DllImport("shell32.dll", CharSet = CharSet.Unicode)]        public static extern int SHQueryRecycleBin(                [MarshalAs(UnmanagedType.LPTStr)]                String pszRootPath,                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.        }        /// <summary>        /// Call SHEmptyRecycleBin() method of shell32 dll to empty recycle bin.        /// </summary>        [System.Runtime.InteropServices.DllImport("Shell32.dll")]        static extern int SHEmptyRecycleBin(IntPtr hwnd, string psrRootPath, RecycleFlags dwFlags);        /// <summary>        /// This method will empty recycle bin without prompting confirmation message.        /// </summary>        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.        }    }}
```

---

Original Source: https://www.mindstick.com/blog/188/recycle-bin-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
