SHAddToRecentDocs (shell32)
Last changed: -67.40.219.42

.
Summary

C# Signature:

[DllImport("shell32.dll", CharSet = CharSet.Ansi)]

public static extern void

  SHAddToRecentDocs(ShellAddToRecentDocsFlags flag, string path);

[DllImport("shell32.dll")]

public static extern void

  SHAddToRecentDocs(ShellAddToRecentDocsFlags flag, IntPtr pidl);

User-Defined Types:

public enum ShellAddToRecentDocsFlags {

  Pidl = 0x001,
  Path = 0x002,

}

Notes:

None.

Tips & Tricks:

Helper:

public static void AddToRecentDocs(string path) {

  SHAddToRecentDocs(ShellAddToRecentDocsFlags.Path, path);

}

Sample Code:

class ShellApi {

  public enum ShellAddToRecentDocsFlags {
    Pidl = 0x001,
    Path = 0x002,
  }

  [DllImport("shell32.dll", CharSet = CharSet.Ansi)]
  public static extern void
    SHAddToRecentDocs(ShellAddToRecentDocsFlags flag, string path);

  [DllImport("shell32.dll")]
  public static extern void
    SHAddToRecentDocs(ShellAddToRecentDocsFlags flag, IntPtr pidl);

  public static void AddToRecentDocs(string path) {
    SHAddToRecentDocs(ShellAddToRecentDocsFlags.Path, path);
  }

}

class RatesOfReturnForm : Form {

  ...
  void OpenDocument(string newFilename) {
    ...
    // Put the file into the Start->Documents list
    ShellApi.AddToRecentDocs(newFilename);
  }

  void SaveDocument(SaveType type) {
    ...
    // Put the file into the Start->Documents list
    ShellApi.AddToRecentDocs(newFilename);
  }
  ...

}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation