none
Restore (undelete) file from Recycle Bin

    Question

  • Hi all. Is anyone know the way to restore files and folders from recycle bin with C#? Only article that I could found is http://www.codeproject.com/KB/shell/recyclebin.aspx but it is written with C++ and I not able to translate it to C#. Thanks in advance.
    Thursday, June 25, 2009 6:58 PM

Answers

  • Here's code for Vista and XP.  This is ugly code and only demonstrates the concept.  I  have no idea why the recyclers are not documented better. 

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.VisualBasic.FileIO;
    using System.IO;
    namespace RestoreFromRecycle
    {
      public partial class Form1 : Form
      {
        public Form1()
        {
          InitializeComponent();
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
          string TextFile = "D:\\Temp\\Text.txt";
          string TextForFile = "This is text for the TextFile.";
          File.WriteAllText(TextFile, TextForFile);
          FileSystem.DeleteFile(TextFile, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
          if (FindFileInRecycleBin(TextFile))
          {
            Console.WriteLine("File Restored" + " " + File.ReadAllText(TextFile));
          }
        }
        public bool FindFileInRecycleBin(string FileName)
        {
          string DU = null;
          foreach (string D in Directory.GetDirectories(Path.GetPathRoot(FileName)))
          {
            DU = D.ToUpper();
            if (DU.Contains("$RECYCLE.BIN"))
            {
              return VistaRecycleBin(FileName, D);
            }
            else if (DU.Contains("RECYCLER"))
            {
              return XPRecycler(FileName, D);
            }
          }
          return false;
        }
        public bool XPRecycler(string FileName, string D)
        {
          foreach (string DSub in Directory.GetDirectories(D))
          {
            foreach (string F in Directory.GetFiles(DSub))
            {
              if (Path.GetFileName(F) == "INFO2")
              {
                byte[] FileData = File.ReadAllBytes(F);
                int FileIncrement = 800;
                int FileNameOffset = 20;
                int FileNumberOffset = 280;
                int I = 0;
                int C = 0;
                int Offset = 0;
                do
                {
                  I = Offset + FileNameOffset;
                  if (I > FileData.Length)
                  {
                    return false;
                  }
                  StringBuilder SB = new StringBuilder();
                  do
                  {
                    C = FileData[I];
                    if (C == 0)
                    {
                      break;
                    }
                    SB.Append((char)(C));
                    I += 1;
                  } while (!(I == 0));
                  if (SB.ToString() == FileName)
                  {
                    string RecycleFileName = DSub + "\\D" + FileName[0] + FileData[Offset + FileNumberOffset].ToString() + Path.GetExtension(FileName);
                    File.Copy(RecycleFileName, FileName);
                    return true;
                  }
                  Offset += FileIncrement;
                } while (true);
              }
            }
          }
          return false;
        }
        public bool VistaRecycleBin(string FileName, string D)
        {
          foreach (string DSub in Directory.GetDirectories(D))
          {
            foreach (string F in Directory.GetFiles(DSub))
            {
              Console.WriteLine(F);
              if (Path.GetFileName(F).Substring(0, 2) == "$I")
              {
                byte[] FileData = File.ReadAllBytes(F);
                int I = 0;
                int C = 0;
                StringBuilder SB = new StringBuilder();
                I = 24;
                do
                {
                  C = FileData[I];
                  if (C == 0)
                  {
                    break;
                  }
                  SB.Append((char)(C));
                  I += 2;
                } while (!(I == 0));
                if (SB.ToString() == FileName)
                {
                  string RecycleFileName = F.Replace("\\$I", "\\$R");
                  File.Copy(RecycleFileName, FileName);
                  return true;
                }
              }
            }
          }
          return false;
        }
      }
    }
    • Marked as answer by Shoar Friday, July 03, 2009 8:00 PM
    Friday, July 03, 2009 7:11 PM
  • There's no simple API to do it. But the Recycle bin can be manipulated using the shell COM interfaces just like any other (virtual) folder. You get an IShellFolder object for the recycle bin, find the item(s) to wirk with and execute the "undelete" command on them. All the details are in the C++ code in the article you linked to.


    Mattias, C# MVP
    • Marked as answer by Shoar Tuesday, June 30, 2009 11:53 PM
    Friday, June 26, 2009 9:33 AM
  • This is my final answer.  This code has been tested on the following 

         Win2k Pro, XP32 Media Center, XP64, Vista32 Home, Vista64 Ultimate

    all with current updates.

    using System;
    using System.Collections;
    using System.Windows.Forms;
    using System.IO;
    using Shell32; //Reference Microsoft Shell Controls And Automation on the COM tab.
    using System.Runtime.InteropServices;
    using Microsoft.VisualBasic.FileIO;
    namespace RecyclerCS
    {
      public partial class Form1 : Form
      {
        public Form1() {
          InitializeComponent();
        }
        private Shell Shl;
        private const long ssfBITBUCKET = 10;
        private const int recycleNAME = 0;
        private const int recyclePATH = 1;
    
        private void button1_Click(object sender, System.EventArgs e) {
          string S = "This is text in the file to be restored from the Recycle Bin.";
          string FileName = "C:\\Temp\\Text.txt";
          File.WriteAllText(FileName, S);
          Delete(FileName);
          MessageBox.Show(FileName + " has been moved to the Recycle Bin.");
          if (Restore(FileName))
            MessageBox.Show(FileName + " has been restored");
          else
            MessageBox.Show("Error");
          Marshal.FinalReleaseComObject(Shl);
        }
        private void Delete(string Item) {
          FileSystem.DeleteFile(Item, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
          //Gives the most control of dialogs.
        }
        private bool Restore(string Item) {
          Shl = new Shell();
          Folder Recycler = Shl.NameSpace(10);
          for (int i = 0; i < Recycler.Items().Count; i++) {
            FolderItem FI = Recycler.Items().Item(i);
            string FileName = Recycler.GetDetailsOf(FI, 0);
            if (Path.GetExtension(FileName) == "") FileName += Path.GetExtension(FI.Path);
            //Necessary for systems with hidden file extensions.
            string FilePath = Recycler.GetDetailsOf(FI, 1);
            if (Item == Path.Combine(FilePath, FileName)) {
              DoVerb(FI, "ESTORE");
              return true;
            }
          }
          return false;
        }
        private bool DoVerb(FolderItem Item, string Verb) {
          foreach (FolderItemVerb FIVerb in Item.Verbs()) {
            if (FIVerb.Name.ToUpper().Contains(Verb.ToUpper())) {
              FIVerb.DoIt();
              return true;
            }
          }
          return false;
        }
      }
    }
    • Marked as answer by Shoar Sunday, April 11, 2010 10:16 AM
    Sunday, July 05, 2009 2:50 PM

All replies

  • Are you sure that's what you need to do?  Only files deleted by users are saved to the RecycleBin.  Files deleted in code or by network users don't appear in the RecycleBin.
    Thursday, June 25, 2009 10:39 PM
  • Hello John. Files and folders can be moved to recycle bin by Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory and Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile methods with third parameter RecycleOption.SendToRecycleBin. Also SHFileOperation function from shell32.dll can be used but first way is more simple I think. Actually I need to realize "Undo" functionality but I can't find any .NET or WinAPI way to restore files and folders from recycle bin by name.
    Thanks for your reply.
    Thursday, June 25, 2009 11:36 PM
  • There's no simple API to do it. But the Recycle bin can be manipulated using the shell COM interfaces just like any other (virtual) folder. You get an IShellFolder object for the recycle bin, find the item(s) to wirk with and execute the "undelete" command on them. All the details are in the C++ code in the article you linked to.


    Mattias, C# MVP
    • Marked as answer by Shoar Tuesday, June 30, 2009 11:53 PM
    Friday, June 26, 2009 9:33 AM
  • Hi Mattias. Thank you for your reply. It point me to right direction but I have a problem with getting Recycle Bin IShellFolder interface. Here is a code:
    IntPtr recycleBinPidl;
    ShellLib.IShellFolder desktopFolder = ShellLib.ShellFunctions.GetDesktopFolder();
    int result = (int)ShellLib.ShellApi.SHGetFolderLocation(IntPtr.Zero, (int)ShellLib.ShellApi.CSIDL.CSIDL_BITBUCKET, IntPtr.Zero, 0, out recycleBinPidl);
    
    IntPtr ppv;
    //Here an AccessViolationException occurs
    desktopFolder.BindToObject(recycleBinPidl, IntPtr.Zero, ShellLib.ShellGUIDs.IID_IShellFolder, out ppv);
    
    System.Type shellFolderType = ShellLib.ShellFunctions.GetShellFolderType();
    Object obj = Marshal.GetTypedObjectForIUnknown(ppv, shellFolderType);
    IShellFolder recycleBinFolder = (IShellFolder)obj;
    I has got an error in BindToObject line with following message: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
    ShellLib is a shell working library from codeproject ("C# does Shell" articles):
    http://www.codeproject.com/KB/shell/csdoesshell1.aspx
    http://www.codeproject.com/KB/shell/csdoesshell2.aspx
    http://www.codeproject.com/KB/shell/csdoesshell3.aspx

    BindToObject declaration in that library is:
    [PreserveSig]
    Int32 BindToObject(IntPtr pidl, IntPtr pbc, [In()] Guid riid, out IntPtr ppv);
    and looks like it is correct. I also tried to call BindToObject with other PIDLs but still get that error. Any suggestions?

    Friday, June 26, 2009 6:18 PM
  • Hi - I think my information can help.

    In fact, an API exists for this. The API is the = "SHFileOperation" API.

    Here is more information:
    http://wannabedeveloper.spaces.live.com/blog/cns!9051A75A660C95FA!185.entry (Recommended to check first).

    Windows API Guide: SHGetFolderLocation Function
    http://www.xs4all.nl/~rjg70/vbapi/ref/s/shgetfolderlocation.html

    Tips for C# .NET Software Developers: How to programmatically send folders and/or files to the Recycle Bin
    http://www.personalmicrocosms.com/Pages/dotnettips.aspx?c=19&t=22

    Pinvoke: SHFileOperation (Shell32) //The dll.
    http://www.pinvoke.net/default.aspx/shell32.SHFileOperation

    I hope this information was helpful...

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Saturday, June 27, 2009 3:20 PM
  • Hello Fisnik. Thanks for your help. I checked your links about SHFileOperation and looks like it only allows to delete files and folders to recycle bin. It have FO_MOVE, FO_COPY, FO_DELETE and FO_RENAME allowed operations. I thought that I can use FO_MOVE to move file or folder from Recycle Bin but to do that I need to know it's physycal location inside recycle bin. But I can't get physycal location of virtual folder and also files and folders (inside RECYCLER folder) becomes renamed by system after moving to recycle bin.
    Sunday, June 28, 2009 8:07 AM
  • Hi Shoar:

    How are you?

    I found a useful sample, that seems able to restor all files that have been moved to the "Recycle Bin".

    Check out this link: http://www.codeproject.com/KB/shell/recyclebin.aspx

    NOTE: I THINK IT'S IN Win32 C++.

    I hope that link can give you a brief idea.

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Sunday, June 28, 2009 9:37 AM
  • Back to square one.
    Sunday, June 28, 2009 9:54 AM
  • Back to square one.

    Hi JohnWein:

    What do you mean?

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Sunday, June 28, 2009 10:03 AM
  • Hello Fisnik. Yes, it is the only article that I could found which explains how to do that. Unfortunately it is on C++ and I don't know C++ well. Trying to translate this article to C# I get an error (see 4 post of that thread). I already found how to fix that error (BindToObject declaration need ref Guid parameter) and continue to work on it. Thanks.
    Monday, June 29, 2009 1:25 PM
  • Hi,

    nice, good! If you have problem with converting C++2C# then check out this link: http://code2code.net/

    I hope this information was helpful...

    Best regards,
    Fisnik
    Coder24.com
    Monday, June 29, 2009 3:31 PM
  • This code deletes a file and copies it from  the recycle bin to the doriginal location:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using Microsoft.VisualBasic.FileIO;
    namespace RestoreFromRecycle
    {
      public partial class Form1 : Form
      {
        public Form1()
        {
          InitializeComponent();
          
        }
        private void button1_Click_1(object sender, EventArgs e)
        {
        	string TextFile = "D:\\Temp\\Text.txt";
    	    string TextForFile = "This is text for the TextFile.";
    	    File.WriteAllText(TextFile, TextForFile);
    	    FileSystem.DeleteFile(TextFile, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
    	    if (FindFileInRecycleBin(TextFile))
    	    {
    	      Console.WriteLine("File Restored" + " " + File.ReadAllText(TextFile));
    	    }
        }
        public bool FindFileInRecycleBin(string FileName)
        {
    	    foreach (string D in Directory.GetDirectories(Path.GetPathRoot(FileName)))
    	    {
    	      if (D.ToUpper().Contains("RECYCLE"))
    	      {
    		      foreach (string DSub in Directory.GetDirectories(D))
    		      {
    		        foreach (string F in Directory.GetFiles(DSub))
    		        {
    			        if (Path.GetFileName(F).Substring(0, 2) == "$I")
    			        {
    			          byte[] FileData = File.ReadAllBytes(F);
    			          int I, C;
    			          StringBuilder SB = new StringBuilder();
    			          I = 24;
    			          do
    			          {
    				          C = FileData[I];
    				          if (C == 0)
    				          {
    					          break;
    				          }
    				          SB.Append((char)(C));
    				          I += 2;
    			          } while (true);
    			          if (SB.ToString() == FileName)
    			          {
                      File.Copy(F.Replace("\\$I", "\\$R"), FileName);
    				          return true;
    			          }
    			        }
    		        }
    		      }
    	      }
    	    }
    	    return false;
          }
      }
    }
    • Edited by JohnWein Thursday, July 02, 2009 9:46 PM
    Thursday, July 02, 2009 9:40 PM
  • Hello JohnWein. I can't make it work on XP SP2. This cond i tion never becomes true:
    if (Path.GetFileName(F).Substring(0, 2) == "$I").
    F is in form similar to "D:\\RECYCLER\\S-1-5-21-1085031214-884357618-839522115-1003\\Dd1.cs" and has not "$I" substring.
    Friday, July 03, 2009 2:00 PM
  • Here's code for Vista and XP.  This is ugly code and only demonstrates the concept.  I  have no idea why the recyclers are not documented better. 

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.VisualBasic.FileIO;
    using System.IO;
    namespace RestoreFromRecycle
    {
      public partial class Form1 : Form
      {
        public Form1()
        {
          InitializeComponent();
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
          string TextFile = "D:\\Temp\\Text.txt";
          string TextForFile = "This is text for the TextFile.";
          File.WriteAllText(TextFile, TextForFile);
          FileSystem.DeleteFile(TextFile, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
          if (FindFileInRecycleBin(TextFile))
          {
            Console.WriteLine("File Restored" + " " + File.ReadAllText(TextFile));
          }
        }
        public bool FindFileInRecycleBin(string FileName)
        {
          string DU = null;
          foreach (string D in Directory.GetDirectories(Path.GetPathRoot(FileName)))
          {
            DU = D.ToUpper();
            if (DU.Contains("$RECYCLE.BIN"))
            {
              return VistaRecycleBin(FileName, D);
            }
            else if (DU.Contains("RECYCLER"))
            {
              return XPRecycler(FileName, D);
            }
          }
          return false;
        }
        public bool XPRecycler(string FileName, string D)
        {
          foreach (string DSub in Directory.GetDirectories(D))
          {
            foreach (string F in Directory.GetFiles(DSub))
            {
              if (Path.GetFileName(F) == "INFO2")
              {
                byte[] FileData = File.ReadAllBytes(F);
                int FileIncrement = 800;
                int FileNameOffset = 20;
                int FileNumberOffset = 280;
                int I = 0;
                int C = 0;
                int Offset = 0;
                do
                {
                  I = Offset + FileNameOffset;
                  if (I > FileData.Length)
                  {
                    return false;
                  }
                  StringBuilder SB = new StringBuilder();
                  do
                  {
                    C = FileData[I];
                    if (C == 0)
                    {
                      break;
                    }
                    SB.Append((char)(C));
                    I += 1;
                  } while (!(I == 0));
                  if (SB.ToString() == FileName)
                  {
                    string RecycleFileName = DSub + "\\D" + FileName[0] + FileData[Offset + FileNumberOffset].ToString() + Path.GetExtension(FileName);
                    File.Copy(RecycleFileName, FileName);
                    return true;
                  }
                  Offset += FileIncrement;
                } while (true);
              }
            }
          }
          return false;
        }
        public bool VistaRecycleBin(string FileName, string D)
        {
          foreach (string DSub in Directory.GetDirectories(D))
          {
            foreach (string F in Directory.GetFiles(DSub))
            {
              Console.WriteLine(F);
              if (Path.GetFileName(F).Substring(0, 2) == "$I")
              {
                byte[] FileData = File.ReadAllBytes(F);
                int I = 0;
                int C = 0;
                StringBuilder SB = new StringBuilder();
                I = 24;
                do
                {
                  C = FileData[I];
                  if (C == 0)
                  {
                    break;
                  }
                  SB.Append((char)(C));
                  I += 2;
                } while (!(I == 0));
                if (SB.ToString() == FileName)
                {
                  string RecycleFileName = F.Replace("\\$I", "\\$R");
                  File.Copy(RecycleFileName, FileName);
                  return true;
                }
              }
            }
          }
          return false;
        }
      }
    }
    • Marked as answer by Shoar Friday, July 03, 2009 8:00 PM
    Friday, July 03, 2009 7:11 PM
  • I have no idea why the recyclers are not documented better.
    Because it was never intended for you to read/write to them directly like that (have you tried that with UAC turned on and a non-admin account?). You need to use the Shell API. If you do not, you leave open the possibility that your code will break on the next service pack or version of Windows.

    The real question is why didn't the .NET Framework team provide a wrapper for the Shell API.
    Friday, July 03, 2009 7:23 PM
  • Because it was never intended for you to read/write to them directly like that (have you tried that with UAC turned on and a non-admin account?). You need to use the Shell API. If you do not, you leave open the possibility that your code will break on the next service pack or version of Windows.

    The real question is why didn't the .NET Framework team provide a wrapper for the Shell API.

    Show us the Shell API code that works for XP  and Vista. 
    Friday, July 03, 2009 7:51 PM
  • Hello JohnWein. Thanks. That works on XP now. But Tergiver is right. Using Shell API is more difficult way but it will 100% work on any windows system. I spend a lot of time to realize that using windows explorer COM interfaces and I think microsoft could include a more convenient API for such common task in .net framework.
    Friday, July 03, 2009 8:00 PM
  • Hello JohnWein. Thanks. That works on XP now. But Tergiver is right. Using Shell API is more difficult way but it will 100% work on any windows system. I spend a lot of time to realize that using windows explorer COM interfaces and I think microsoft could include a more convenient API for such common task in .net framework.

    I'm not so sure.  From C# you have to use VB just to get a file into the Recycler.  I never did understand the Recycler.  When I delete files on the computers in my network from the network, they don't go to the Recycler, but when I delete the files locally, they do.  If this is critical part of your application, definitely don't use code like I posted here.  Unusual app though.  I can't remember seeing a program that recovers files from the OS recycler.  Apps usually track their files in their own locations independent of the OS.
    Friday, July 03, 2009 8:37 PM
  • I dug into the Shell API and it doesn't appear that it provides a way to restore files. You can list them, count them, and empty the recycler(s), but not restore them. There are some differences between XP and Vista, and Win7 has removed some of the API methods. It looks to me like you have three options for attempting to do what you want:

    1) Use a hack like John has suggested, accepting the fact that you will have to maintain the code indefinately.
    2) Use a hack like the one used in that CodeProject example, calling ShellExecute with the right verb.
    3) Forget about it.

    Personally I would choose #3. Leave the operation of restoring deleted files to Windows Explorer and the user with whom it belongs. If you want to make sure that your app deletes files to the recycler, that should be doable with just a single API call: SHFileOperation.
    Saturday, July 04, 2009 4:21 AM
  • using System;
    using System.Windows.Forms;
    using System.IO;
    using Shell32; //Reference Microsoft Shell Controls And Automation on the COM tab.
    using System.Runtime.InteropServices;
    namespace RecyclerCS
    {
      public partial class Form1 : Form
      {
        public Form1()
        {
          InitializeComponent();
        }
        private Shell Shl;
        private const long ssfBITBUCKET = 10;
        private const int recycleNAME = 0;
        private const int recyclePATH = 1;
        private void button1_Click(object sender, System.EventArgs e)
        {
          string S = "This is text in the file to be restored from the Recycle Bin.";
          string FileName = "D:\\Temp\\Text.txt";
          File.WriteAllText(FileName, S);
          MoveToRecycleBin(FileName);
          MessageBox.Show(FileName + " has been moved to the Recycle Bin.");
          if (RestoreFromRecycleBin(FileName))
          {
            MessageBox.Show(FileName + " has been restored");
          }
          else
          {
            MessageBox.Show("Error");
          }
          Marshal.FinalReleaseComObject(Shl);
        }
        public void MoveToRecycleBin(string Item)
        {
          Shl = new Shell();
          Folder Recycler = Shl.NameSpace(10);
          Recycler.MoveHere(Item, 0); //Look in help for options
        }
        public bool RestoreFromRecycleBin(string Item)
        {
          Shl = new Shell();
          Folder Recycler = Shl.NameSpace(10);
          System.Collections.IEnumerator ItemsEnum = Recycler.Items().GetEnumerator();
          while (ItemsEnum.MoveNext())
          {
            string FileName = Recycler.GetDetailsOf(ItemsEnum.Current, 0);
            string FilePath = Recycler.GetDetailsOf(ItemsEnum.Current, 1);
            if (Item == Path.Combine(FilePath, FileName)
            {
              Shl.NameSpace(FilePath).MoveHere(ItemsEnum.Current, 0); //Look in help for options
              return true;
            }
          }
          return false;
        }
      }
    }
    
    
      
    
    Saturday, July 04, 2009 3:59 PM
  • This is my final answer.  This code has been tested on the following 

         Win2k Pro, XP32 Media Center, XP64, Vista32 Home, Vista64 Ultimate

    all with current updates.

    using System;
    using System.Collections;
    using System.Windows.Forms;
    using System.IO;
    using Shell32; //Reference Microsoft Shell Controls And Automation on the COM tab.
    using System.Runtime.InteropServices;
    using Microsoft.VisualBasic.FileIO;
    namespace RecyclerCS
    {
      public partial class Form1 : Form
      {
        public Form1() {
          InitializeComponent();
        }
        private Shell Shl;
        private const long ssfBITBUCKET = 10;
        private const int recycleNAME = 0;
        private const int recyclePATH = 1;
    
        private void button1_Click(object sender, System.EventArgs e) {
          string S = "This is text in the file to be restored from the Recycle Bin.";
          string FileName = "C:\\Temp\\Text.txt";
          File.WriteAllText(FileName, S);
          Delete(FileName);
          MessageBox.Show(FileName + " has been moved to the Recycle Bin.");
          if (Restore(FileName))
            MessageBox.Show(FileName + " has been restored");
          else
            MessageBox.Show("Error");
          Marshal.FinalReleaseComObject(Shl);
        }
        private void Delete(string Item) {
          FileSystem.DeleteFile(Item, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
          //Gives the most control of dialogs.
        }
        private bool Restore(string Item) {
          Shl = new Shell();
          Folder Recycler = Shl.NameSpace(10);
          for (int i = 0; i < Recycler.Items().Count; i++) {
            FolderItem FI = Recycler.Items().Item(i);
            string FileName = Recycler.GetDetailsOf(FI, 0);
            if (Path.GetExtension(FileName) == "") FileName += Path.GetExtension(FI.Path);
            //Necessary for systems with hidden file extensions.
            string FilePath = Recycler.GetDetailsOf(FI, 1);
            if (Item == Path.Combine(FilePath, FileName)) {
              DoVerb(FI, "ESTORE");
              return true;
            }
          }
          return false;
        }
        private bool DoVerb(FolderItem Item, string Verb) {
          foreach (FolderItemVerb FIVerb in Item.Verbs()) {
            if (FIVerb.Name.ToUpper().Contains(Verb.ToUpper())) {
              FIVerb.DoIt();
              return true;
            }
          }
          return false;
        }
      }
    }
    • Marked as answer by Shoar Sunday, April 11, 2010 10:16 AM
    Sunday, July 05, 2009 2:50 PM