none
How to recover deleted files? RRS feed

  • Question

  • Hi!

    I want to know how the recovery softwares recover deleted files and .Net languages can do this ?


    Wednesday, January 15, 2014 12:39 PM

Answers

  • Hi,

    This thread suggests that it is possible to undelete from the recycle bin using .Net code: http://social.msdn.microsoft.com/Forums/vstudio/en-US/05f1476f-a101-4766-847b-0bdf4f6ad397

    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;
        }
      }
    }

    JohnWein's example is using C#, but you could convert them to VB using this tool: converter.telerik.com


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 16, 2014 5:53 AM
    Moderator
  • In Visual Basic it cannot be done unless you are calling an external library that can perform NTFS operations. This requires knowledge of a language such as C++ and NTFS. See the below link for more info:

    http://www.codeproject.com/Articles/9293/Undelete-a-file-in-NTFS


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, January 16, 2014 1:19 PM

All replies

  • There is nothing built into .NET that enables the recovery of deleted files. This operation requires calls to the Windows API or lower level disk operations.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, January 15, 2014 2:12 PM
  • OK 

    How to do that

    Wednesday, January 15, 2014 4:55 PM
  • Hi,

    This thread suggests that it is possible to undelete from the recycle bin using .Net code: http://social.msdn.microsoft.com/Forums/vstudio/en-US/05f1476f-a101-4766-847b-0bdf4f6ad397

    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;
        }
      }
    }

    JohnWein's example is using C#, but you could convert them to VB using this tool: converter.telerik.com


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 16, 2014 5:53 AM
    Moderator
  • In Visual Basic it cannot be done unless you are calling an external library that can perform NTFS operations. This requires knowledge of a language such as C++ and NTFS. See the below link for more info:

    http://www.codeproject.com/Articles/9293/Undelete-a-file-in-NTFS


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, January 16, 2014 1:19 PM
  • Android Data Recovery can do this. First launch the program on your computer, second connect your phone to computer, third debug USB, fourth scan your phone, at last you can recover deleted files on Android if you are an Android user.
    Monday, February 24, 2014 2:48 AM
  • Android Data Recovery can do this. First launch the program on your computer, second connect your phone to computer, third debug USB, fourth scan your phone, at last you can recover deleted files on Android if you are an Android user.

    Good answer. To what question I have no clue.

    I suppose if the question had been how to start a car your answer would have been how to start a steam locomotive.


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Monday, February 24, 2014 3:33 AM