Move file to trashbin

[DllImport("shell32.dll", CharSet = CharSet.Auto)]
static extern int SHFileOperation(ref SHFILEOPSTRUCT FileOp);
 
private void MoveToBin(string filePath)
{
    SHFILEOPSTRUCT fileop = new SHFILEOPSTRUCT();
    fileop.wFunc = FO_DELETE;
    fileop.pFrom = filePath + '\0' + '\0';
    fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
    SHFileOperation(ref fileop);
}
 
private const int FO_DELETE = 3;
private const int FOF_ALLOWUNDO = 0x40;
private const int FOF_NOCONFIRMATION = 0x0010;
 
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)]
public struct SHFILEOPSTRUCT
{
    public IntPtr hwnd;
    [MarshalAs(UnmanagedType.U4)]
    public int wFunc;
    public string pFrom;
    public string pTo;
    public short fFlags;
    [MarshalAs(UnmanagedType.Bool)]
    public bool fAnyOperationsAborted;
    public IntPtr hNameMappings;
    public string lpszProgressTitle;
}
 

Download this snippet

Moves a file to the windows trashbin.

Twitter Twitter

2 Comments to “ Move file to trashbin”

  1. Anonymous  on Mar 15, 2010

    FZ6zSH <a href="http://gbkrqdfesqck.com/">gbkrqdfesqck</a>, [url=http://wqgsozsymbna.com/]wqgsozsymbna[/url], [link=http://qipiwviazjwd.com/]qipiwviazjwd[/link], http://imkkrpnizqlx.com/

  2. Anonymous  on Jun 10, 2010

    P49jy8 <a href="http://qtqwlnzskidb.com/">qtqwlnzskidb</a>, [url=http://ieuotjtqnyzl.com/]ieuotjtqnyzl[/url], [link=http://ydqqdvhspeng.com/]ydqqdvhspeng[/link], http://qyedyohyjoej.com/

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>