1
我試着去使用此功能,但得到的一些錯誤:我如何獲得目標文件在我的硬盤上的快捷方式?
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));
}
第一個錯誤是上線:
Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
上線(Shell32.ShellLinkObject)的右手folderItem.GetLink 即時得到錯誤:
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?
而就在最後一行:
Console.WriteLine(GetShortcutTargetFile(path));
錯誤是在:GetShortcutTargetFile(路徑)函數是靜態的,但我刪除了靜態,然後我在最後一行mgetting錯誤。
Error 4 An object reference is required for the non-static field, method, or property 'GatherLinks.Form1.GetShortcutTargetFile(string)
我該如何解決所有的錯誤以及如何獲得所有的目標文件的短路?
這個想法是知道讀取一個快捷方式文件。例如,把它們全部放在List中。 – user1741587
谷歌可以很好地解決這兩個錯誤... – TGlatzer