-5

I have made a c# app to access files that was in the Recent Files. But i need to open the file when clicked. How can i do it?

Code : https://i.stack.imgur.com/I4pSD.jpg

NB: My app shows files that has been used by the user recently. The name of the file he used will be showed when user switches on the pc next time. So that he can access it quickly and easily. I have accessed the Recently Used Files in windows and retrieved the file name. But I don't know about the code to open that file. That's what I am asking. File name is directly retrieved from the recent files.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    `I can't access the directory of the file.` Why not? – LarsTech Apr 24 '19 at 16:34
  • I mean i can't open the file path that has been retrieved from the Recent Files. Is there any way? – Fazil Aboobacker Apr 24 '19 at 16:37
  • 1
    What recent files are you talking about? Your own? Visual Studio? Show us your code that isn't working. – LarsTech Apr 24 '19 at 16:38
  • Recently Used Files in windows. It shows recently openend files and softwares. That is what iam talking about – Fazil Aboobacker Apr 24 '19 at 16:40
  • 1
    We will need a bit more detail about what you are trying to do. Some of your code examples would be useful here. – Rob Goodwin Apr 24 '19 at 16:40
  • 1
    You are being very vague about this recent file list. How are you creating it? Populating it? Using it? – LarsTech Apr 24 '19 at 16:42
  • My app shows files that has been used by the user recently. The name of the file he used will be showed when user switches on the pc next time. So that he can access it fastly and easily. I have accessed the Recently Used Files in windows and retireved the file name. But i don't know about the code to open that file. That's what iam asking. – Fazil Aboobacker Apr 24 '19 at 16:49
  • 1
    Can you share some code? Maybe that'll help clarify what the question is. You say that you have the file name, but you don't know how to open it? What's wrong with `File.Open`? – Raymond Chen Apr 24 '19 at 16:53
  • https://imgur.com/a/rSfSRrx – Fazil Aboobacker Apr 24 '19 at 17:06
  • 1
    Please do not post images of code. Copy/paste the code into an [edit] into your question instead. Also, consider fully reading the [ask] section to understand why there's a disconnect to what details we need to help you fully. – gravity Apr 24 '19 at 17:22

1 Answers1

0

Ideally you should be using the IShellFolder interface to enumerate and execute items in the Recent folder but I assume you are not going to do that and instead keep the code you already have.

Environment.SpecialFolder.Recent is indeed the folder where these files are kept. These .lnk files are shortcuts and when you want to execute them you must make sure you have a full path (Environment.SpecialFolder.Recent + filename + ".lnk") and pass this to Process.Start:

using System.Diagnostics;
...
Process myProcess = new Process()
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.FileName = fullpathtoshortcut;
myProcess.Start();

If you want to be a good citizen and do this properly with the shell interfaces you probably need to get the shell API Code Pack.

Anders
  • 97,548
  • 12
  • 110
  • 164