<分区>
Possible Duplicate:
Get target of shortcut folder
例如,在 C:\TEMP\
中,我有一个名为 test.dll
的快捷方式,该快捷方式将指向文件名 test.dll
我只想从快捷方式获取文件本身的路径名。 所以,我在另一个递归函数中调用这个函数,每次从我的硬盘中的另一个目录中放入这个函数。
例如,第一个目录是 C:\TEMP
然后在 C:\TEMP
中有快捷方式文件,我只想获取该文件的路径.在 C:\TEMP
中进行测试,我现在有 3 个文件:
hpwins23.dat
hpwmdl23.dat
hpwmdl23.dat -Shortcut
(C:\TEMP\hpwmdl23.dat
)
所以,我想得到的是快捷方式的路径名,在本例中是 C:\TEMP
我尝试使用这个函数:
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);
if (folder == null)
{
}
else
{
FolderItem folderItem = folder.ParseName(filenameOnly);
if (folderItem != null)
{
Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
return link.Path;
}
}
return string.Empty;
}
但是当我使用该函数并使用它的快捷方式时,我在该行收到异常错误:
Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink //The exception is: NotImplementedException: The method or operation is not implemented
我应该怎么做才能解决它?
这是完整的异常错误信息:
System.NotImplementedException
was caught
Message=The method or operation is not implemented.
Source=GatherLinks
StackTrace:
atShell32.FolderItem.get_GetLink()
atGatherLinks.Form1.GetShortcutTargetFile(String shortcutFilename)
in
D:\C-Sharp\GatherLinks\GatherLinks\GatherLinks\Form1.cs
:line
904
atGatherLinks.Form1.offlinecrawling