The following code shows you how to empty a recycle bin.
using System.Runtime.InteropServices;
// Libraries to import
[DllImport("shell32.dll", EntryPoint = "SHEmptyRecycleBinA", ExactSpelling = true, CharSet = CharSet.Ansi,SetLastError = true)]
private static extern int SHEmptyRecycleBin(int hWnd, string pszRootPath, int dwFlags);
[DllImport("shell32.dll",ExactSpelling=true,CharSet=CharSet.Ansi,SetLastError=true)]
private static extern int SHUpdateRecycleBinIcon();
private const int SHERB_NOCONFIRMATION = 0x1;
private const int SHERB_NOSOUND = 0x4;
private void emptyRecycleBin()
{
SHEmptyRecycleBin(this.Handle.ToInt32(),string.Empty,Convert.ToInt32(SHERB_NOCONFIRMATION + SHERB_NOSOUND));
SHUpdateRecycleBinIcon();
}
private void btnEmpty_Click(object sender, EventArgs e)
{
try
{
emptyRecycleBin();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
0 comments:
Post a Comment