Búsqueda


Categorías

C# [15]
PHP [6]
Zend [1]
FileMaker [1]
.NET [6]
CVS [3]
General [9]
Javascript [2]
Paypal [1]
.NET Compact Framework [3]
C++ [1]
mysql [4]
Linux [1]

Últimos post

Dónde guardar los archivos de configuración en ClickOnce
phpinfo: Valores en error_reporting
Notes about Zend Server and Zend Studio setup
What's new in C# 4
Resolving a 'sticky tag is not a branch' error
Resumen del CodeCamp
CodeCamp Tarragona 2009
Acerca de la calidad del código
ClickOnce en Linux
Programando en PHP (y con CVS) en Visual Studio 2008

Sindicación

RSS 0.90
RSS 1.0
RSS 2.0
Atom 0.3

Send a file to the recycle bin in C#

ctg | 26 Mayo, 2006 00:02

using System;
using System.IO;
using System.Runtime.InteropServices;

/// <summary>
/// Class to delete a file and move it to Recycle bin
/// </summary>
class RecycleBin
{
     private const int FO_DELETE          = 3;
     private const int FOF_ALLOWUNDO      = 0x40;
     private const int FOF_NOCONFIRMATION = 0x0010;
   
     [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);
     /// <summary>
     /// Delete a file and move it to Recycle bin
     /// </summary>
     /// <param name="fileName">File to delete</param>
     public static void Send(string fileName)
     {
          if (File.Exists(fileName) )
          {
               SHFILEOPSTRUCT shf = new SHFILEOPSTRUCT();
               shf.hwnd = IntPtr.Zero;
               shf.wFunc = (int) FO_DELETE;
               shf.pTo = null;
               shf.pFrom = fileName + "\0\0";
               shf.fFlags = (ushort) FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
               shf.fAnyOperationsAborted = false;
               shf.hNameMappings = IntPtr.Zero;
               SHFileOperation(ref shf);
          }
     }
}
 

Posted in C# . Comentario: (0). Retroenlaces:(0). Enlace
«Next post | Previous post»

Comentarios

Deja un comentario
















En que mes se celebra la navidad: