例如,在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
被抓住
消息 =的方法或操作未實現。
源 =GatherLinks
堆棧跟蹤:
在Shell32.FolderItem.get_GetLink()
在GatherLinks.Form1.GetShortcutTargetFile(String shortcutFilename)
在D:\C-Sharp\GatherLinks\GatherLinks\GatherLinks\Form1.cs
:line
904
在GatherLinks.Form1.offlinecrawling
此用戶最有可能要求解決的符號鏈接(沒有快捷方式在.LNK),在這種情況下,該代碼將失敗。你需要在PInvoke中使用'GetFinalPathNameByHandle()'。示例代碼可以在[此處輸入](http://chrisbensen.blogspot.com/2010/06/getfinalpathnamebyhandle.html)中找到。 – ykay