1

How can I retrieve a list of most recent opened/accessed files, not just from Open File dialog or MRU list, via C# without having to scan the entire hard drive?

Thanks

Getting the last opened file in fileopen dialog box http://www.codeproject.com/Articles/3636/Add-Most-Recently-Used-Files-MRU-List-to-Windows-A

Community
  • 1
  • 1
Swab.Jat
  • 1,210
  • 1
  • 14
  • 19
  • 1
    Are you after all files in the system, or just files opened within your application? – Dai Jan 04 '14 at 01:41
  • 1
    Thanks, http://www.irongeek.com/i.php?page=security/windows-forensics-registry-and-file-system-spots#Recently%20opened%20files%20from%20Windows%20Explorer contains a lot of information. However, I was testing with for example Open File from Notepad++, the registry keys there didn't capture the information. I tried drag file from Explorer to Notepad++, also tried open it from Notepad++ Open File Dialog, also tried save it. But, no joy. Any reliable mechanism out there? – Swab.Jat Jan 06 '14 at 01:14

1 Answers1

2

(Posting the link to the answer as a public courtesy to get this off the unanswered list, as I don't have close privileges yet.)

string path = Environment.GetFolderPath(Environment.SpecialFolder.Recent);
var files = Directory.EnumerateFiles(path);

CREDIT TO AS-CII

ORIGINAL ANSWER HERE

Community
  • 1
  • 1
CodeMouse92
  • 6,840
  • 14
  • 73
  • 130
  • 1
    Thanks but no joy - see above comment where I tested open/save file with Notepad++ for instance. SpecialFolder.Recent did not capture it. Neither was the information found in registry keys found under http://www.irongeek.com/i.php?page=security/windows-forensics-registry-and-file-system-spots#Recently%20opened%20files%20from%20Windows%20Explorer – Swab.Jat Jan 06 '14 at 01:15
  • 1
    Dont think you're right, I just tested with Notepad++. "Environment.SpecialFolder.Recent" is able to capture if I open a file from Notepad++ via standard "Open File Dialog". If I DRAG DROP a file from Explorer to Notepad++, this won't capture it. Further, "Environment.SpecialFolder.Recent" is same as "C:\Users\$USERNAME$.$WORKSTATIONNAME$\AppData\Roaming\Microsoft\Windows\Recent" –  Jan 06 '14 at 01:49
  • Of course, again, I reposted this from another question in which the answer works, so I can't really take credit for it either way. However, as I know enough about C# to make me dangerous, and quite a lot about Windows in general, I would recommend checking into whether you have something that is wiping your Recent Documents on your computer, Swab.Jat. I know CCleaner removes those as part of the cleaning process (optionally), as do a lot of cleaning software titles. Just a random idea, it may not be that at all. – CodeMouse92 Jan 06 '14 at 03:04