none
how to create a program for recoveing deleted text files...?

    General discussion

  • hi 

    i want to write a program for showing list of deleted files in c#

    and is there any way to write a code for recover those files through c#....?

    thanks in advence...


    programmer on .net

    Monday, March 12, 2012 11:59 AM

All replies

  • Hi programmer,

    Welcome to the MSDN forum!

    If you mean those files in the recycle bin, I think you may get started with this tutorial:

    Working With The Windows Recycle Bin With C#
    http://www.dreamincode.net/forums/topic/164491-working-with-the-windows-recycle-bin-with-c%23/  

    In this series we will look at some functionality the Shell32.dll gives you for working with the Windows Recycle Bin. In this first entry we will look at how we can do 2 things:

    1. List all the files in the Recycle Bin
    2. Display the size of each item 

        //using Shell32;
        //using System.Runtime.InteropServices;
    
    
        public class RecycleBinItem
        {
            public string FileName { get; set; }
            public string FileType { get; set; }
            public string FileSize { get; set; }
        }
    
        public class RecycleBin
        {
            public List<RecycleBinItem> GetRecycleBinItems()
            {
                try
                { 
                    // Create a new instance of the Shell32 interface
                    Shell shell = new Shell();
                    List<RecycleBinItem> list = new List<RecycleBinItem>();
    
                    // create a folder item to our Recycle Bin
                    Folder recycleBin = shell.NameSpace(10);
    
                    foreach (FolderItem2 f in recycleBin.Items())
                    {
                        list.Add(
                            new RecycleBinItem
                            {
                                FileName=f.Name,
                                FileType = f.Type,
                                FileSize =GetSize(f).ToString()                    
                            });
                    }
    
                    // release
                    Marshal.FinalReleaseComObject(shell);
    
                    //return the list
                    return list;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return null;
                }
            }
    
            public double GetSize(FolderItem folderItem)
            {
                if (!folderItem.IsFolder)
                    return (double)folderItem.Size;
    
                // create a new Shell32.Folder item
                Folder folder = (Folder)folderItem.GetFolder;
                
                double size = 0;
    
                foreach (FolderItem2 f in folder.Items())
                {
                    size += GetSize(f);
                }
    
                return size;
            }     
        }
    
       
            static void Main(string[] args)
            {
                RecycleBin bin = new RecycleBin();
    
                Console.WriteLine("Items In Recycle Bin");
    
                foreach(RecycleBinItem item in bin.GetRecycleBinItems())
                       Console.WriteLine(string.Format("File: {0} => Size: {1} => Type: {2}", 
                           item.FileName, item.FileSize, item.FileType));
    
                Console.ReadLine();
            }

    Hope it helps.

    Have a nice day!

    yoyo


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
     

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Wednesday, March 14, 2012 6:38 AM
    Moderator
  • hello,

    this is possible to recover deleted files through c# code.please refer this link........

    http://www.dreamincode.net/forums/topic/202422-c%23-recover-deleted-files-from-the-system/

    http://stackoverflow.com/questions/3813024/deleted-file-recovery-program-using-c-c

    http://stackoverflow.com/questions/1352550/how-can-i-undelete-a-file-using-c


    Tarun singh Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights


    • Edited by Tarun00007 Saturday, March 17, 2012 2:10 PM
    Wednesday, March 14, 2012 9:48 AM
  • hi Yoyo Jiang

    thanks its working

    i have one more doubt

    if the file is even deleted from recycle bin...,

    is there any way to recover that file through c# program.....?



    programmer on .net

    Wednesday, March 14, 2012 4:46 PM
  • Hi programmer,

    I guess there is. I remembered that there are some software for recovering these files being deleted from the recycle bin. 

    You can refer to the following thread with hot discussion on this issue:

    How can I recover deleted files (with shift-del)
    http://answers.microsoft.com/en-us/windows/forum/windows_vista-files/how-can-i-recover-deleted-files-with-shift-del/13b1eaad-d41a-4e77-91c5-f0bc9590de7d  

    When a file is deleted from your computer, its contents aren't immediately destroyed. Windows simply marks the hard drive space as being available for use by changing one character in the file table. If you manage to start an undelete process before Windows overwrites that part of hard disk with new files. You can set that flag back to "on" and get your file.

     

    As I know, you can download some free recovery software as follow to recover deleted files.

     

    Note:Stop using the current disk as main disk, please keep it unchangeable before recovering the files.

     

    1.Panda Recovery

     

      Pandora Recovery actually recovers files permanently removed from Recycle Bin, files originally deleted using Shift + Delete keys bypassing Recycle Bin and files deleted from DOS prompt. Pandora Recovery allows you to find and recover recoverable deleted files from NTFS-formatted volumes, regardless of their type - you can recover pictures, songs, movies or documents. Setup file is 2.12 MB in size. For more information, please visit the following link.

     

    Panda Recovery

     

    2.TOKIWA DataRecovery

      

      DataRecovery is freeware and written by TOKIWA to undelete accidentally deleted files even from recycle bin. It supports FAT12, FAT16, FAT32 and NTFS undeletion. Even in both NTFS compressed files and EFS encrypted files. Zip file is only 198 KB in size, no installation required and it’s portable.

     

    Download: TOKIWA DataRecovery

     

    3.Undelete Plus

     

      Undelete Plus is a quick and effective way to restore accidentally deleted files. It can also recover files that have been emptied from the Recycle Bin, permanantly deleted files within Windows using the Shift + Delete, and files that have been deleted from within a Command Prompt. Undelete Plus works under Win 95/98/Me/NT/2000/XP/2003/Vista operating systems. The program supports all Windows file systems for hard and floppy drives including FAT12/16/32,NTFS/NTFS5 and image recovery from CompactFlash, SmartMedia, MultiMedia and Secure Digital cards. Program is only 583 KB in size and requires no installation. Portable. For more information, please visit the following web site.

     

     Undelete Plus

     

    However, if you are not familiar with above application, I highly recommend that you contact Data Recovery Company for support.


    Hope it helps.

    yoyo


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

    Thursday, March 15, 2012 2:46 AM
    Moderator
  • hi Yoyo Jiang

    is it possible to write the program for that

    i mean i want to write a program for recover deleted files from recycle bin

    is it possible...?



    programmer on .net

    Saturday, March 17, 2012 2:05 PM
  • Yes. I guess so. There are already some third party products on this issue, so that there must be a way to implement the demand.

    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, March 21, 2012 6:21 AM
    Moderator
  • To recover files which are deleted from recycle bin you need to use lowlevel IO. You need to access the drive using winapi and you need knowledge about the NTFS filesystem.

    I don`t want to offend you, but after taking a look at your threads, i guess at the moment this task does not match your current skills.


    Hannes

    If you have got questions about this, just ask.

    In a perfect world,
    users would never enter data in the wrong form,
    files they choose to open would always exist
    and code would never have bugs.

    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/


    • Edited by Heslacher Wednesday, March 21, 2012 7:22 AM
    Wednesday, March 21, 2012 7:22 AM