恢复已删除的文件 [英] Recovery of deleted files

查看:98
本文介绍了恢复已删除的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..朋友正在做恢复已删除文件的项目请任何人打电话给我如何使用asp.net从回收站中删除文件C#

解决方案

代码如下:

  public  List< recyclebinitem> GetRecycleBinItems()
{

try
{
// 创建Shell32接口的新isntance
Shell shell = new 贝壳();
List< recyclebinitem> list = new List< recyclebinitem>();

// 创建一个文件夹项目到我们的回收站
文件夹recycleBin = shell.NameSpace( 10 );

// 现在让我们循环浏览Folder对象中的所有项目

// 并将它们添加到通用列表

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

catch (例外情况)
{
Console.WriteLine( string .Format( 访问回收站时出错:{0},ex.Message));

return null ;
}
}







欲了解更多详情,请访问以下链接:

http:/ /www.dreamincode.net/forums/topic/164491-working-with-the-windows-recycle-bin-with-c%23/ [ ^ ]


首先,您需要从您的应用程序请求管理权限。对于Windows 7等Windows版本,以具有管理员权限的用户身份登录是不够的。通常,用户可以以管理员身份执行您的应用程序,但这不会那么优雅。如果您请求如果您要求应用程序通过应用程序清单以管理员身份运行,则用户只需要输入确认密钥。



您将需要将am应用程序清单文件添加到项目中。在食谱配方的层面上,这里解释如下:

http://stackoverflow.com/questions/7666408/how-to-request-administrator-permissions-when-the-program-starts [ ^ ],

http:// stackoverflow .com / questions / 8802261 / c-sharp-exe-should-for-run-as-administrator-prompt-when-opened [ ^ ]。



然后你需要找到移动回收站的文件。通常,它们被放置在目录


Recycle.Bin 中。不幸的是,此目录未在 System.Environment.SpecialFolder 中列出。其他所有内容都减少到 System.IO.File.Copy System.IO.File.Move

http:// msdn .microsoft.com / zh-cn / library / system.io.file.copy%28v = vs.110%29.aspx [ ^ ],

< a href =http://msdn.microsoft.com/en-us/library/system.io.file.move.aspx> http://msdn.microsoft.com/en-us/library/system.io .file.move.aspx [ ^ ]。



祝你好运,

-SA

hi.. friends am doing project on Recovery of deleted files pls any one tel me How to get deleted files from recycle bin using asp.net C#

解决方案

Code is as follows:

public List<recyclebinitem> GetRecycleBinItems()  
 {  

     try 
     {  
         //create a new isntance 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);  
 
         //now let's loop through all the Items in our Folder object  

         //and add them to a generic list  

         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 ex)  
     {  
         Console.WriteLine(string.Format("Error accessing the Recycle Bin: {0}", ex.Message));  

        return null;  
     }  
 } 




For more details visit following link:
http://www.dreamincode.net/forums/topic/164491-working-with-the-windows-recycle-bin-with-c%23/[^]


First, you need to request administrative privileges from your application. With Windows versions like Windows 7, login in as a user with administrator privileges is not enough. Normally, the user can execute your application "as administrator", but this won't be as elegant. If you request If you request the application to be run "as administrator" by the application manifest, the user would only need to hit a confirmation key.

You will need to add am application manifest file to the project. At the level of a cookbook recipe, this is explained here:
http://stackoverflow.com/questions/7666408/how-to-request-administrator-permissions-when-the-program-starts[^],
http://stackoverflow.com/questions/8802261/c-sharp-exe-should-ask-for-run-as-administrator-prompt-when-opened[^].

Then you need to locate the file moved the the recycle bin. Normally, they are placed is the directory


Recycle.Bin. Unfortunately, this directory is not listed in System.Environment.SpecialFolder. Everything else is reduced to System.IO.File.Copy or System.IO.File.Move:
http://msdn.microsoft.com/en-us/library/system.io.file.copy%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.io.file.move.aspx[^].

Good luck,
—SA


这篇关于恢复已删除的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆