Skip to content

Instantly share code, notes, and snippets.

@lockworld
Last active June 19, 2017 19:00
Show Gist options
  • Save lockworld/1501cf759f2d91c0260b95f587962e76 to your computer and use it in GitHub Desktop.
Save lockworld/1501cf759f2d91c0260b95f587962e76 to your computer and use it in GitHub Desktop.
Working with files in a C# application
using Shell32;
using System;
namespace RecycleBin
{
class Program
{
static void Main(string[] args)
{
Type t = Type.GetTypeFromProgID("Shell.Application");
dynamic shell = Activator.CreateInstance(t);
Folder RecycleBin = shell.NameSpace(ShellSpecialFolderConstants.ssfBITBUCKET); //ssfBITBUCKET is the user's recycle bin
RecycleBin.MoveHere(@"C:\Users\dlockwood\Documents\Temporary Files\DeleteMe.txt ",new int[] { 4, 64,512,9182 });
/*
4: Do not display a progress dialog box
64: Preserve undo information, if possible
512: Do not confirm the creation of a new directory if the operation requires one to be created
9182: Do not move connected files as a group. Only move the specified files
*/
}
}
}
Move file to Recyle Bin:
http://nd.fyi/csRecycleBin
ShellSpecialFolderConstants:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb774096(v=vs.85).aspx
Folder.MoveHere Options:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb787874(v=vs.85).aspx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment