No built in functions that I can find, but a quick google search turns up this post.
For reference:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)] public struct SHFILEOPSTRUCT { public IntPtr hwnd; [MarshalAs(UnmanagedType.U4)] public int wFunc; public string pFrom; public string pTo; public short fFlags; [MarshalAs(UnmanagedType.Bool)] public bool fAnyOperationsAborted; public IntPtr hNameMappings; public string lpszProgressTitle;
}
[DllImport("shell32.dll", CharSet=CharSet.Auto)] static extern int SHFileOperation(ref SHFILEOPSTRUCT FileOp); const int FO_DELETE = 3; const int FOF_ALLOWUNDO = 0x40; const int FOF_NOCONFIRMATION = 0x10; //Don't prompt the user.;
Here's what I did, add Microsoft.VisualBasic as a reference and then do:
Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory(filename or folder, Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin);
Prashant: MSDN has an example of the deleting to the recycle bin How to: Delete a File in Visual Basic ... also remember one can F1 on any item in Visual Studio editor to be taken to help.<br>
C# Send Files or Folder to Recycle Bin
Preston Park
- Add a reference to Microsoft.VisualBasic assembly. The needed class is found in this library.
- Add this using statement to the top of the file using Microsoft.VisualBasic.FileIO;
- Use FileSystem.DeleteFile to delete a file, it has the option to specify recycle bin or not.
- Use FileSystem.DeleteDirectory to delete a directory with the option to specify to send it to the recycle bin or not.
If you are in VB.Net the need to reference the VB assembly is not required, just reference the namespace.HarryBedi
Hey soconne
Can u send the code that u have used to delete a file and put it in Recyclebin,
Byee and TC
Zclai
For reference:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
public struct SHFILEOPSTRUCT
{
public IntPtr hwnd;
[MarshalAs(UnmanagedType.U4)] public int wFunc;
public string pFrom;
public string pTo;
public short fFlags;
[MarshalAs(UnmanagedType.Bool)] public bool fAnyOperationsAborted;
public IntPtr hNameMappings;
public string lpszProgressTitle;
static extern int SHFileOperation(ref SHFILEOPSTRUCT FileOp);
const int FO_DELETE = 3;
const int FOF_ALLOWUNDO = 0x40;
const int FOF_NOCONFIRMATION = 0x10; //Don't prompt the user.;
To use the API:
SHFILEOPSTRUCT shf = new SHFILEOPSTRUCT();
SHFileOperation(ref shf);shf.wFunc = FO_DELETE;
shf.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
shf.pFrom = "C:\\test.txt";
Avhacker
Delete File:
My.Computer.FileSystem.DeleteFile("THE FILE TO DELETE", FileIO.UIOption.AllDialogs, FileIO.RecycleOption.SendToRecycleBin)
Delete Directory:
My.Computer.FileSystem.DeleteDirectory("THE DIRECTORY TO DELETE", FileIO.UIOption.AllDialogs, FileIO.RecycleOption.SendToRecycleBin)
Have fun and be carefull.
Tony
LouArnold
ron nash
Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory(filename or folder,
Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs,
Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin);
Dick Campbell