12-30-2011، 04:13 PM
Instructions: This one is simple, call the method, check the results. Add reference to this Namespace:
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.ComponentModel;
کد:
//Namespace reference
using System.Runtime.InteropServices;
/// <summary>
/// enum to hold the recycle
/// bin flags
/// </summary>
enum RecycleFlags : uint
{
SHERB_NOCONFIRMATION = 0x00000001,
SHERB_NOPROGRESSUI = 0x00000002,
SHERB_NOSOUND = 0x00000004
}
/// <summary>
/// Import Win32 DLL for emptying the recycle bin
/// </summary>
/// <param name="hwnd"></param>
/// <param name="pszRootPath"></param>
/// <param name="dwFlags"></param>
/// <returns></returns>
[DllImport("Shell32.dll", CharSet = CharSet.Unicode)]
static extern uint SHEmptyRecycleBin(IntPtr hwnd,string pszRootPath,RecycleFlags dwFlags);
public bool EmptyRecycleBin()
{
try
{
uint result = SHEmptyRecycleBin(IntPtr.Zero, null, RecycleFlags.SHERB_NOSOUND | RecycleFlags.SHERB_NOCONFIRMATION);
if (result > 0)
return true;
else
throw new Win32Exception(Marshal.GetLastWin32Error());
}
catch (Exception ex)
{
this._message = string.Format("Error emptying Recycle Bin: {0}", ex.Message);
return false;
}
}
گروه دور همی پارسی کدرز
https://t.me/joinchat/GxVRww3ykLynHFsdCvb7eg
https://t.me/joinchat/GxVRww3ykLynHFsdCvb7eg