Feedback

C# - Datei in Papierkorb verschieben

Veröffentlicht von am 1/9/2007
(4 Bewertungen)
Verschiebt eine Datei in den Papierkorb
[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;
}

Kommentare zum Snippet

 

Logge dich ein, um hier zu kommentieren!