Send a File to the Recycle Bin

后端 未结 8 1171
北海茫月
北海茫月 2020-11-27 10:59

Currently I\'m using the following function

file.Delete();

But how can I use this function to send a file to the recycle bin instead of jus

8条回答
  •  野性不改
    2020-11-27 11:43

    The following solution is simpler than the other ones:

    using Shell32;
    
    static class Program
    {
        public static Shell shell = new Shell();
        public static Folder RecyclingBin = shell.NameSpace(10);
    
        static void Main()
        {
            RecyclingBin.MoveHere("PATH TO FILE/FOLDER")
        }
    }
    

    You can use other functionalities of the recycle bin using this library.

    First, don't forget to add the library "Microsoft Shell Controls And Automation" (from the COM menu), to be able to use the Shell32 namespace. It will be dynamically linked to your project, instead of being compiled along with your program.

提交回复
热议问题