How to Move files to the recycle bin

2019-06-15 14:21发布

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?

5条回答
干净又极端
2楼-- · 2019-06-15 14:36

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

查看更多
趁早两清
3楼-- · 2019-06-15 14:43

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

查看更多
看我几分像从前
4楼-- · 2019-06-15 14:52

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

查看更多
做自己的国王
5楼-- · 2019-06-15 14:55

Have you got a

using Microsoft.VisualBasic.FileIO;

at the top of your page?

查看更多
Fickle 薄情
6楼-- · 2019-06-15 14:58

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 );
查看更多
登录 后发表回答