Im trying to use this function but getting some errors:
public string GetShortcutTargetFile(string shortcutFilename)
{
string pathOnly = System.IO.Path.GetDirectoryName(shortcutFilename);
string filenameOnly = System.IO.Path.GetFileName(shortcutFilename);
Shell shell = new Shell();
Folder folder = shell.NameSpace(pathOnly);
FolderItem folderItem = folder.ParseName(filenameOnly);
if (folderItem != null)
{
Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
return link.Path;
}
return string.Empty;
}
static void Main(string[] args)
{
const string path = @"C:\link to foobar.lnk";
Console.WriteLine(GetShortcutTargetFile(path));
}
The first error is on the line :
Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
On the right hand of the line (Shell32.ShellLinkObject)folderItem.GetLink Im getting errors:
Error 2 One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll?
And on the line in the end:
Console.WriteLine(GetShortcutTargetFile(path));
The error is on the: GetShortcutTargetFile(path) the function was static but i removed the static and then i mgetting the error in the last line.
Error 4 An object reference is required for the non-static field, method, or property 'GatherLinks.Form1.GetShortcutTargetFile(string)
How can i fix all the errors and how to get all the shortucts that target files ?