Answered Delete to recycle bin

cbreemer

Well-known member
Joined
Dec 1, 2021
Messages
184
Programming Experience
10+
I was googling for a way to delete a file to the recycle bin from C#. Couldn't find anything, but found several posts, even YouTube videos, showing how to do it using a referenced VisualBasic assembly. It works great, but it feels a bit kludgy and I am puzzled as why VisualBasic has this but C# apparently doesn't (or if it does, it seems well nigh impossible to find).
Any ideas ?
 
Back then, DevDiv had assigned particular personas to their target audiences. Based on the personas, they created feature sets that they expected would provide the best developer experiences for them. Some PM must have determined that file deletion for VB.NET developers should mimic a user doing a file delete and therefore use the ShellAPIs which support the recycle bin, while C#, F#, IronPython, and other .NET developers should mimic what a C/C++ programmer would do when deleting a file, and bypass the recycle bin.

Just reference the VB assembly since it is released as part of the .NET Runtime and don't bother thinking about it. If you really think that extra assembly is really a drag on your app, then do the appropriate P/Invoke calls to call tht ShellAPIs.
 
Back then, DevDiv had assigned particular personas to their target audiences. Based on the personas, they created feature sets that they expected would provide the best developer experiences for them. Some PM must have determined that file deletion for VB.NET developers should mimic a user doing a file delete and therefore use the ShellAPIs which support the recycle bin, while C#, F#, IronPython, and other .NET developers should mimic what a C/C++ programmer would do when deleting a file, and bypass the recycle bin.
Thanks for your reply. I know one couldn't do this in C/C++, but that doesn't seem a good reason to not include it in C# with its so much richer feature set.
Just reference the VB assembly since it is released as part of the .NET Runtime and don't bother thinking about it. If you really think that extra assembly is really a drag on your app, then do the appropriate P/Invoke calls to call tht ShellAPIs.
Oh I'm sure it does not matter a jot in performance whether I call a C# or VB assembly. It beats the hell out of having to write extra code for it, and come to think of it it's really not much different from using a NuGet package for something or other.
 
I know one couldn't do this in C/C++
You can do it in C/C++, but most programmers at that time wouldn't be thinking in terms of expecting file deletion to go to the recycle bin. They would would be thinking in terms of their previous OS experience where file deletion is permanent.
 
You can do it in C/C++, but most programmers at that time wouldn't be thinking in terms of expecting file deletion to go to the recycle bin. They would would be thinking in terms of their previous OS experience where file deletion is permanent.
Yes, a recycle bin would have been an alien concept to the Unix weenies 😀 But when I programatically delete a photo from my smartphone I'd like it to go to the bin, just in case I get second thoughts.
 
Also recall that Windows didn't get a recycle bin until Win95. Prior to that, there was a small cottage industry of people selling undelete utilities.

As I was falling asleep last night, a thought came to mind. It's possible that the PMs were thinking that a VB.NET developer would be unable to figure out how to call the ShellAPI, but a C# would be able to do so if they needed to. This seems much like they thought that a VB.NET developer would be unable to parse CSV and fixed field text files, but a C# developer would hence the existence of the TextFieldParser class.
 
Also recall that Windows didn't get a recycle bin until Win95. Prior to that, there was a small cottage industry of people selling undelete utilities.

As I was falling asleep last night, a thought came to mind. It's possible that the PMs were thinking that a VB.NET developer would be unable to figure out how to call the ShellAPI, but a C# would be able to do so if they needed to. This seems much like they thought that a VB.NET developer would be unable to parse CSV and fixed field text files, but a C# developer would hence the existence of the TextFieldParser class.
It is great fun trying to fathom the reasoning of the MS developers. Ultimately futile though 😁
Say, it worries me some that you even think about this stuff while going to sleep ! Think of fluffy sheep, pretty girls, whatever !
 
Back
Top Bottom