How to Move files to the recycle bin
Asked Answered
G

5

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?

Greggrega answered 6/4, 2009 at 11:18 Comment(7)
Have you tried Google? google.com/search?q=C%23+delete+file+to+recycle+binTaille
There really should be a "too easy to find on Google" reason for closing a question.Jestinejesting
agreed, you really should try google first. Or at least report what you've tried?Dysart
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.Kentigerma
NOW you're talking, guys! I've always discouraged easily Google-able questions.Manda
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?Phytosociology
Possible duplicate of Send a File to the Recycle BinAnthropo
K
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

Kentigerma answered 6/4, 2009 at 11:27 Comment(3)
+1 This does indeed work. I was just going to post the same answer myself.Lyric
Just remember to add a reference to Microsoft.VisualBasic.dllLyric
Btw, it uses P/Invoke, as it seems from ReflectorTaille
Y
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 );
Yacov answered 17/5, 2012 at 9:57 Comment(0)
O
0

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

Obsolescent answered 6/4, 2009 at 11:21 Comment(0)
M
0

Have you got a

using Microsoft.VisualBasic.FileIO;

at the top of your page?

Misuse answered 6/4, 2009 at 11:51 Comment(0)
T
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

Timecard answered 18/8, 2012 at 22:59 Comment(1)
@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 ;-)Timecard

© 2022 - 2024 — McMap. All rights reserved.