Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to Empty recycle bin using VB.NET

Author: DevASP
Download Source Code : 321_EmptyRecycleBin.zip

This article is about how you can empty your recycle bin using the window API calls.

  • Steps you will do. 
  • Start visual studio and create a new window application. 
  • Set the following properties of your form.

 

Name = frmMain

Text = Empty Recycle Bin

FormBoarderStyle = FixedSingle

Maximize = False

 

  • Drop a label control and set the following properties.
  • Text = Click on the button to empty your recycle bin. 
  • Drop a button control on your form and set its following properties.

 

Name = btEmpty

Text = Empty Recycle Bin

 

  • Now open your code window and write the following code in the code window.

 

The following code is to be placed just before the statement of your form designer. For example, code generated by the form designer.

 

Your code which is given below.

 

#End Region

 

Code is as follows:

 

Private Shared m_vb6FormDefInstance As frmMain

 

    Private Shared m_InitializingDefInstance As Boolean

 

Public Shared Property DefInstance() As frmMain

 

        Get

 

 If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then

 

     m_InitializingDefInstance = True

 

     m_vb6FormDefInstance = New frmMain

 

     m_InitializingDefInstance = False

 

     End If

 

      DefInstance = m_vb6FormDefInstance

 

    End Get

 

        Set(ByVal Value As frmMain)

 

            m_vb6FormDefInstance = Value

 

        End Set

 

    End Property

  •  Now declare the following function to call API’s. 

Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hWnd As Integer, ByVal pszRootPath As String, ByVal dwFlags As Integer) As Integer

 

 Const SHERB_NOPROGRESSUI As Short = &H2S

  • In the click event of your button write the following code which will call the API function declare above to empty recycle bin.

 

Dim retvaL As Object

 

        retvaL = SHEmptyRecycleBin(frmMain.DefInstance.Handle.ToInt32, "", SHERB_NOPROGRESSUI)

 

Article Comments
Useful app, but for my needs I want to be able to empty the re-cycle bin without the confirmation dialog "are you sure you want to delete everything in the re-cycle bin" appearing. Is that possible.

Regards

Michael Bond

Posted on 6/8/2006 10:24:16 AM by Michael Bond

change &H2S to &H1S

Posted on 10/10/2006 9:08:56 PM by Chris

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to Validate Text fields for Numeric Data

Disclaimer - Privacy
© 2002-2017 DevASP.net