[C#]获取最近在Windows上所使用的文件

class RecentlyFileHelper
{
public static string GetShortcutTargetFile(string shortcutFilename)
{
var type = Type.GetTypeFromProgID("WScript.Shell");
object instance = Activator.CreateInstance(type);
var result = type.InvokeMember("CreateShortCut", BindingFlags.InvokeMethod, null, instance, new object[] { shortcutFilename });
var targetFile = result.GetType().InvokeMember("TargetPath", BindingFlags.GetProperty, null, result, null) as string;
return targetFile;
}

public static IEnumerable<string> GetRecentlyFiles()
{
var recentFolder = Environment.GetFolderPath(Environment.SpecialFolder.Recent);
return from file in Directory.EnumerateFiles(recentFolder)
where Path.GetExtension(file) == ".lnk"
select GetShortcutTargetFile(file);

}
}

posted @ 2014-06-11 14:47  想飞的水  阅读(489)  评论(0编辑  收藏  举报