Recycle Files With VB.NET 2005
Another Reason To Move Up to VB.NET 2005
Most VB programmers know about the various ways to delete a file that have always been available in Visual Basic. There's the Kill function in VB 6 and VB.NET. The FileSystemObject in VB 6 does the trick. The File and FileInfo objects in VB.NET delete files. But there's one thing that none of these can do and that is to delete files into the Recycle bin.
Your hard disk contains a hidden folder named Recycled (Recycler in NTFS) that contains files deleted in Windows Explorer, My Computer or Windows-based programs. When you delete a file, the complete path and file name is stored in a hidden file called Info and the deleted file is renamed. So you can't just move a file to recycle it.
In the past, you had to use the SHFileOperation Win32 API to delete a file and place it in the Recycle Bin. (MSDN has instructions showing how to do that if you need them.) But one of the functions that was added with the My namespace in VB.NET 2005 was the ability to move files easily into the Recycle Bin.
Simply code ...
My.Computer.FileSystem.DeleteFile(<path string>, _ <display dialog option>, _ FileIO.RecycleOption.SendToRecycleBin)
The "display dialog option" even gives you the ability to show those handy windows to confirm the file deletion and display errors if something goes wrong. What could be easier?
Now ... if only there was an "undelete" option too. I haven't found one of those. Any help?


Comments
I’m not sure if an undelete option exists. I don’t think I’ve used a microsoft program that had one, and I’d think they’d know the most about their API’s. Usually once you delete something the undo option disappears in Office programs for example.