C # delete files and folders to the recycle bin,
From: http://www.soaspx.com/dotnet/csharp/csharp_20120926_9646.html If C # code is used to delete files or folders. Files and folders are directly deleted, rather than deleted to the recycle bin. You can call the methods provided by Microsoft. VisualBasic. dll. Add a reference named Microsoft. VisualBasic. dll to the project, and then add a namespace. using Microsoft.VisualBasic.FileIO; The sample code is as follows: UsingSystem; usingMicrosoft. visualBasic. fileIO; namespaceleaver {classProgram {staticvoidMain (string [] args) {Console. writeLine ("delete a file to the recycle bin"); stringfilepath = "leaver.txt"; FileSystem. deleteFile (filepath, UIOption. onlyErrorDialogs, RecycleOption. sendToRecycleBin); Console. writeLine ("File deleted"); Console. writeLine ("delete a folder to the recycle bin"); stringdirpath = "leaver"; FileSystem. deleteDirectory (dirpath, UIOption. onlyErrorDialogs, RecycleOption. sendToRecycleBin); Console. writeLine ("folder deleted ");}} |