14

I need to Move a file to recycle bin in .net 2003

I added microsft.visualbasic.runtime dll from refrence, but I could not able to get filesystem.deletedirectory, So what to do..Can any one help me?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Have you tried Google? http://www.google.com/search?q=C%23+delete+file+to+recycle+bin – abatishchev Apr 06 '09 at 11:20
  • There really should be a "too easy to find on Google" reason for closing a question. – Matt Hamilton Apr 06 '09 at 11:21
  • agreed, you really should try google first. Or at least report what you've tried? – Davy Landman Apr 06 '09 at 11:25
  • 1
    I also agree with Matt on this. Chances are this guy just registered to ask this, then finds the answer before he gets and answer here, and then is never heard from again. – Marcus L Apr 06 '09 at 11:28
  • NOW you're talking, guys! I've always discouraged easily Google-able questions. – Cerebrus Apr 06 '09 at 11:34
  • 6
    This question WAS the top result on Google when I searched. Isn't the point of stackoverflow to be a comprehensive database of programmer questions and answers, rather than to simply fill in the gaps? – gillonba Jan 30 '12 at 22:01
  • Possible duplicate of [Send a File to the Recycle Bin](http://stackoverflow.com/questions/3282418/send-a-file-to-the-recycle-bin) – MicroVirus Jun 21 '16 at 10:55

5 Answers5

24

I found this, don't know if it works, but it's worth a shot.

using Microsoft.VisualBasic;

string path = @"c:\myfile.txt";
FileIO.FileSystem.DeleteDirectory(path, FileIO.UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);

EDIT: Wise words from Nifle: Just remember to add a reference to Microsoft.VisualBasic.dll

Marcus L
  • 4,030
  • 6
  • 34
  • 42
2

Basically, between the reference at the top and actually calling the method you need the full name (after adding the library of course)

You can either fully call it:

Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory(
    path,
    FileIO.UIOption.OnlyErrorDialogs,
    RecycleOption.SendToRecycleBin);

OR you can add the reference to the top with the others:

using Microsoft.VisualBasic.FileIO

and then

FilesSystem.DeleteDirectory( etc );
Deadly-Bagel
  • 1,612
  • 1
  • 9
  • 21
0

Using

FileIO.FileSystem.DeleteDirectory(path, FileIO.UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);

needs: 00:00:00.4036573 to delete one file. Using

[DllImport("shell32.dll", CharSet = CharSet.Auto)]
private static extern int SHFileOperation(ref SHFILEOPSTRUCT FileOp);

only needs: 00:00:00.1107684 to delete one file.

An implementation can be found there: Send a File to the Recycle Bin

Community
  • 1
  • 1
jwillmer
  • 3,570
  • 5
  • 37
  • 73
  • @xmenW.K. Sorry, it's to long ago but I think I used 1000 generated files and devided the time that was used to delete them to get an average time ;-) – jwillmer Jan 27 '14 at 20:54
0

This might help you. Looks like you need to either add a reference to Microsoft.VisualBasic.dll or use P/Invoke.

Jakob Christensen
  • 14,826
  • 2
  • 51
  • 81
0

Have you got a

using Microsoft.VisualBasic.FileIO;

at the top of your page?

cjk
  • 45,739
  • 9
  • 81
  • 112