SKULL VIRUS

sebelum anda membaca sila register forum ini..

credit by:skull virus malaysia

Join the forum, it's quick and easy

SKULL VIRUS

sebelum anda membaca sila register forum ini..

credit by:skull virus malaysia

SKULL VIRUS

Would you like to react to this message? Create an account in a few clicks or log in to continue.
SKULL VIRUS

skull virus untuk membantu anda dalam bidang ICT


    How to delete a file or folder to Recyclebin

    avatar
    zulkar1993
    Admin


    Posts : 47
    Points : 133
    Reputation : -1
    Join date : 13/10/2012
    Age : 31
    Location : malaysia

    How to delete a file or folder to Recyclebin Empty How to delete a file or folder to Recyclebin

    Post by zulkar1993 Wed Mar 27, 2013 10:44 pm

    f we delete file or folder using C# code, it will be deleted from system permanently. Yesterday I was searching for a solution, which helps me to delete file to recycle bin. There is no direct API* available in .Net which helps me to achieve this. Later I found an option using SHFileOperation function. And here is the implementation, which help to delete file or folder to Recyclebin.

    [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;
    }

    [DllImport("shell32.dll", CharSet = CharSet.Auto)]
    public static extern int SHFileOperation(ref SHFILEOPSTRUCT FileOp);

    public const int FO_DELETE = 3;
    public const int FOF_ALLOWUNDO = 0x40;
    public const int FOF_NOCONFIRMATION = 0x10; // Don't prompt the user

    And you can use this function like this

    var shf = new Win32.SHFILEOPSTRUCT();
    shf.wFunc = Win32.FO_DELETE;
    shf.fFlags = Win32.FOF_ALLOWUNDO;
    shf.pFrom = @"c:\myfile.txt" + '\0' + '\0';
    Win32.SHFileOperation(ref shf);

    The pFrom parameter can be either file or folder.

    Happy Programming Smile

    * This is not 100% true. We can do this by using Microsoft.VisualBasic namespace. And here is the implementation.

    using Microsoft.VisualBasic;

    string path = @"c:\myfile.txt";
    FileIO.FileSystem.DeleteDirectory(path,
    FileIO.UIOption.OnlyErrorDialogs,
    RecycleOption.SendToRecycleBin);

    credit by:http://www.codeproject.com/

      Current date/time is Thu May 02, 2024 9:27 pm