lockworld
6/9/2017 - 2:02 PM

Working with files in a C# application

Working with files in a C# application

Move file to Recyle Bin:
http://nd.fyi/csRecycleBin

ShellSpecialFolderConstants:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb774096(v=vs.85).aspx

Folder.MoveHere Options:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb787874(v=vs.85).aspx
using Shell32;
using System;

namespace RecycleBin
{
    class Program
    {
            
        static void Main(string[] args)
        {
            Type t = Type.GetTypeFromProgID("Shell.Application");
            dynamic shell = Activator.CreateInstance(t);

            Folder RecycleBin = shell.NameSpace(ShellSpecialFolderConstants.ssfBITBUCKET);  //ssfBITBUCKET is the user's recycle bin
            RecycleBin.MoveHere(@"C:\Users\dlockwood\Documents\Temporary Files\DeleteMe.txt ",new int[] { 4, 64,512,9182 });
                                                    /*
                                                    4:          Do not display a progress dialog box
                                                    64:        Preserve undo information, if possible
                                                    512:     Do not confirm the creation of a new directory if the operation requires one to be created
                                                    9182:  Do not move connected files as a group. Only move the specified files
                                                    */
        }
    }
}