1

When we open text file using notepad, a shortcut file is created in recent folder. How notepad do it internally. I tried to open text file using

Process.Start("C:\test.txt");

But no shortcut was created. But for other files, like image, video and audio, recent file shortcuts are being created. by using

Process.start("c:\summer.jpeg");

I also tried using the commands below.

ProcessStartInfo psi = new ProcessStartInfo();
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.UseShellExecute = true;
psi.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System);
psi.FileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "notepad.exe");
psi.Arguments = "C:\test.txt";

Process.Start(psi);
Junaid
  • 1,004
  • 8
  • 24
  • As @user287107's answer indicates, this is opt-in behaviour - as you should realise you'd want it to be. Programs can open hundreds of files for various reasons (DLLs, resources, fonts, configuration, etc) and most of those files are completely irrelevant to the user. – Damien_The_Unbeliever May 08 '15 at 06:40
  • Maybe you are referring to JumpLists? https://msdn.microsoft.com/en-us/library/system.windows.shell.jumplist.addtorecentcategory%28v=vs.110%29.aspx – azt May 08 '15 at 07:41

1 Answers1

2

you can try to use the function SHAddToRecentDocs to add the file to the recent list.

https://msdn.microsoft.com/en-us/library/windows/desktop/bb762105(v=vs.85).aspx

here you find the C# invoke:

http://www.pinvoke.net/default.aspx/shell32.shaddtorecentdocs

user287107
  • 9,286
  • 1
  • 31
  • 47