I want a WPF button that will open explorer.exe in Windows 7|8 directly into the "Recycle Bin". This is because my app erases a lot of files, and I want to provide the user with a quick way to restore files. The command line arguments don't work, possibly because the "Recycle Bin" is a virtual directory. I have tried using "$Recycle Bin". Explorer.exe /root, where a is a virtual file fails. Trying to protect the space in Recycle\ Bin does not seem to work as well.
Here is working code from Scott Powell that I tested and am using. Thank you Scott@
private void ExploreTrashBin ( )
{
String str_RecycleBinDir = String.Format(@"C:\$Recycle.Bin\{0}", UserPrincipal.Current.Sid);
Process . Start ( "explorer.exe" , str_RecycleBinDir );
}
private void TrashBin_Button_Click ( object sender , RoutedEventArgs e )
{
ExploreTrashBin ( );
}
Indeed, it is strongly recommended to start your programming journey with C language as it helps to understand a lot of underlying processes on the ground level, which enhances your fundamental knowledge & boosts your confidence, which further makes it easier for you to learn other high-level programming languages as ...
C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.
You could execute following command in order to achieve this,
start shell:RecycleBinFolder
From your C# code you could use,
System.Diagnostics.Process.Start("explorer.exe", "shell:RecycleBinFolder");
It is already implemented in Microsoft.VisualBasic.FileIO.FileSystem class in .Net (so C# natively supports the use of this).
This way, you don't need run shell command : just delete files/folders programmatically as if done interactively with Windows Explorer!
using Microsoft.VisualBasic.FileIO;
FileSystem.DeleteFile(...)
FileSystem.DeleteDirectory(...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With