From: http://www.soaspx.com/dotnet/csharp/csharp_20120926_9646.html If you use C # code to delete files or folders. Files and folders are deleted directly, rather than deleted to the Recycle Bin. You can call the method provided by Microsoft.VisualBasic.dll. First add a reference named Microsoft.VisualBasic.dll to the project, and then add the namespace Using Microsoft.VisualBasic.FileIO; The final example code is as follows: usingsystem;usingmicrosoft.visualbasic.fileio;namespaceleaver{ classprogram { Staticvoidmain ( String[]args) { Console.WriteLine ("Delete Files to Recycle Bin"); Stringfilepath= "Leaver.txt"; Filesystem.deletefile (filepath,uioption.onlyerrordialogs,recycleoption.sendtorecyclebin); Console.WriteLine ("Delete file complete"); Console.WriteLine ("Delete folder to Recycle Bin"); Stringdirpath= "Leaver"; Filesystem.deletedirectory (dirpath,uioption.onlyerrordialogs,recycleoption.sendtorecyclebin); Console.WriteLine ("Delete folder Complete"); } } |
C # Delete files and folders to the Recycle Bin