Search code examples
c#processstartinfojump-list

Is there a way to use ProcessStartInfo that will create a shortcut in the Windows recent items jump list?


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!


Solution

  • 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");