This is a discussion on Empty a recycle bin in C# within the C# Programming forums, part of the Software Development category; How to empty a recycle bin in C#?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| hi, try this code.... Dim Action As New ShellActions Action.EmptyRecycleBin() Public Class ShellActions Shared Function _ SHEmptyRecycleBin(ByVal hWnd As Integer, ByVal pszRootPath As String, _ ByVal dwFlags As Integer) As Integer End Function Sub New() EmptyRecycleBin() End Sub Sub EmptyRecycleBin(Optional ByVal rootPath As String = "", _ Optional ByVal noConfirmation As Boolean = True, Optional ByVal NoProgress _ As Boolean = True, Optional ByVal NoSound As Boolean = True) Const SHERB_NOCONFIRMATION = &H1 Const SHERB_NOPROGRESSUI = &H2 Const SHERB_NOSOUND = &H4 If rootPath.Length > 0 AndAlso rootPath.Substring(1, 2) <> ":\" Then rootPath = rootPath.Substring(0, 1) & ":\" End If Dim flags As Integer = (noConfirmation And SHERB_NOCONFIRMATION) Or _ (NoProgress And SHERB_NOPROGRESSUI) Or (NoSound And SHERB_NOSOUND) SHEmptyRecycleBin(0, rootPath, flags) End Sub |
| |||
| Hi, We can clear the RecycleBin simply by using the Shell32.dll in C#. ![]() Just import the dll using System.Runtime.InteropServices call the function SHEmptyRecycleBin . shell32.dll is a library which contains Windows Shell API functions, which are used when opening web pages and files. Here is sample code … ![]() Code: 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); Code: try
{
uint result = SHEmptyRecycleBin(IntPtr.Zero, null, 0);
MessageBox.Show(this,"Done !","Empty the
RecycleBin",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(Exception ex)
{
MessageBox.Show(this, "Failed ! " + ex.Message, "Empty the
RecycleBin", MessageBoxButtons.OK, MessageBoxIcon.Stop);
Application.Exit();
} For more….just visit to below, Empty the Recycle Bin using C#. - The Code Project - C# Programming S.Vinothkumar: Empty the Recycle Bin using C#
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to remove empty or null rows from a dataview | it.wily | C# Programming | 2 | 02-10-2008 07:34 AM |
| what is the Difference between isset() and empty() . | raj | PHP Programming | 2 | 07-19-2007 01:03 AM |
| Outlook - Mail subject empty alert | priyan | Microsoft | 1 | 07-11-2007 07:57 AM |