0

I'm opening a PDF file from a directory under the %username%\My Documents folder location using ProcessStart and ProcessInfoStart. If I open the file programmatically, the pdf does not show under the C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Recent Items location - but does show on the Jump List for Adobe Acrobat. If I double-click the file, in file explorer, the PDF will show in the Recent Items location.

I tried saving and opening the PDFs as HTML docs and they still won't show up under "Recent Items". Tried directly invoking Acrobat when starting ProcessStartInfo.

var processStart = new ProcessStartInfo("AcroRd32.exe");

I've tried directly opening File Explorer and passing in "/select" with the file path - it will open in Acrobat but not show in Recent Items.

 var processStart = new ProcessStartInfo("AcroRd32.exe");
var savePath = @"C:\Users\%username%\My Documents\PDFs\MyPdf.pdf";
//processStart.Arguments = savePath;
processStart.WindowStyle = ProcessWindowStyle.Minimized;
var fileArgs = $"/select, ""{savePath}""";
processStart.Arguments = fileArgs;
processStart.UseShellExecute = false;
Process.Start(processStart);

Is there a way to refresh/update the Recent Items jumplist when opening up a file location with ProcessStart? Thanks!

  • `Process` will not do this - you need to talk directly to the Windows shell. Some information [here](https://docs.microsoft.com/en-us/dotnet/api/system.windows.shell.jumplist?view=netframework-4.8). – 500 - Internal Server Error Aug 20 '19 at 16:24

1 Answers1

1

There is an option to manually add it via SHAddToRecentDocs API:

Here is the C# example:

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

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

Usage:

SHAddToRecentDocs(ShellAddToRecentDocsFlags.Path, @"C:\Users\%username%\My Documents\PDFs\MyPdf.pdf");
EylM
  • 5,196
  • 2
  • 13
  • 24
  • 1
    @EyIM, thank you for that! I kept coming across the `SHAddToRecentDocs` but didn't understand how to invoke it in C#. It works perfectly! – Jake_TheCoder Aug 20 '19 at 18:30