IT Community - Software Programming, Web Development and Technical Support

Empty a recycle bin in C#

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#?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 08-08-2007, 08:37 AM
garunprasad garunprasad is offline
D-Web Trainee
 
Join Date: Mar 2007
Location: Chennai
Posts: 45
garunprasad is on a distinguished road
Send a message via ICQ to garunprasad Send a message via AIM to garunprasad Send a message via MSN to garunprasad Send a message via Yahoo to garunprasad Send a message via Skype™ to garunprasad
Thumbs up Empty a recycle bin in C#

How to empty a recycle bin in C#?
__________________
G.A.P
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-08-2007, 08:42 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Empty a recycle bin in C#

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-25-2007, 02:56 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Wink Re: Empty a recycle bin in C#

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!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 10:57 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0