View the list of recently opened files in Windows width C#

Each time that you open a file from Windows Explorer or from a standard open/save dialog-box, the name of the file that you opened is recorded by the Windows operating system.

Some of the names are saved into the ‘Recent’ folder. Other are saved into the Registry.

“Recent” Folder

The “Recent” folder is usually located under C:\Documents and Settings\[Your Profile]\Recent (The path is different under Windows Vista), and it contains shortcuts to the recently opened files.

Using Environment.SpecialFolder Enumeration you can retrieve directory paths to system special folders as “Recent” folder .


Registry: If you are using open/save dialog box for file selection, the selected file name is added to the files list under


The following method will give you an idea how to read saved data:

public static string GetRecentlyOpenedFile(string extention)
   RegistryKey regKey = Registry.CurrentUser;
   string recentFile = string.Empty;
   regKey = regKey.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\OpenSaveMRU");

   if (string.IsNullOrEmpty(extention))
       extention = "html";

   RegistryKey myKey = regKey.OpenSubKey(extention);

   if (myKey == null && regKey.GetSubKeyNames().Length > 0)
       myKey = regKey.OpenSubKey(
                      regKey.GetSubKeyNames()[regKey.GetSubKeyNames().Length - 2]);
   if (myKey != null)
       string[] names = myKey.GetValueNames();
       if (names != null && names.Length > 0)
           recentFile = (string)myKey.GetValue(names[names.Length - 2]);
    return recentFile;




  1. Hey… thnkas for this.

    I needed a script to run in our mixed 2007/2010 dev environment. This worked like a charm.

    I made a couple of simple changes to the script to make it more useful to us:
    1. removed the -Append option when writing the header so that it overwrites the output from any previous runs (don’t need to see those results)
    2. added last line to display the results back to the screen: get-content .\results.csv

  2. I’m tynrig to figure out how to modify your script to work in my environment, but having problems.

    We use clusters and the script seems to make the assumption that the value returned for get-exchangeserver will be a physical server name.

    I’m not sure how to go about updating it to recurse out the individual server names from that.Any help greatly appreciated,ThanksPaul

  3. What is String Extension in it,and in which format it return the files..
    How can is display these files on Console…
    can you provide how this function is called from main();
    from function call function return type and function arguments will b much clear

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Captcha Captcha Reload