Thursday, April 28, 2011

How to Move files to the recycle bin

Hi,

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?

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

  • 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

    Nifle : +1 This does indeed work. I was just going to post the same answer myself.
    Nifle : Just remember to add a reference to Microsoft.VisualBasic.dll
    Marcus L : Good point - will add to answer.
    abatishchev : Btw, it uses P/Invoke, as it seems from Reflector
  • Have you got a

    using Microsoft.VisualBasic.FileIO;
    

    at the top of your page?

0 comments:

Post a Comment