如何从文件快捷方式获取路径名?获取异常可能重复:获取快捷方式文件夹的目标例如,在C:\TEMP中有一个名为test.dll的快捷方式,该快捷方式将导致文件名test.dll我只想从中获取路径名自身文档的快捷方式。所以,我在另一个递归函数中调用这个函数,每次都从我硬盘的另一个目录中放置这个函数。比如第一个目录是C:TEMP,C:TEMP中有一个快捷方式文件,我想获取这个文件的路径。在C:\TEMP中测试我现在有3个文件:hpwins23.dathpwmdl23.dathpwmdl23.dat-快捷方式(C:\TEMPhpwmdl23.dat)所以,我想要得到的是快捷方式的路径名,在本例中为C:TEMP我尝试使用这个函数:publicstringGetShortcutTargetFile(stringshortcutFilename){stringfilenameOnly=System.IO.Path.GetFileName(shortcutFilename);shellshell=newShell();文件夹folder=shell.NameSpace(pathOnly);if(folder==null){}else{FolderItemfolderItem=folder.ParseName(filenameOnly);if(folderItem!=null){Shell32.ShellLinkObject链接=(Shell32.ShellLinkObject)folderItem.GetLink;返回链接。路径;}}返回字符串。空;但是当我使用该函数并且它到达快捷方式时,我得到一个异常错误:Shell32.ShellLinkObjectlink=(Shell32.ShellLinkObject)folderItem.GetLink//Theexceptionis:NotImplementedException:ThemethodoroperationisnotimplementedWhatshouldI做修复它?以下是完整的异常错误消息:CaughtSystem.NotImplementedExceptionMessage=Method或operationisnotimplemented。Source=GatherLinksStackTrace:在Shell32.FolderItem.get_GetLink()在GatherLinks.Form1.GetShortcutTargetFile(StringshortcutFilename)在D:C-SharpGatherLinksGatherLinksGatherLinksForm1.cs:line904lineinGatherLinks.Form1.offlinecrawling获取快捷方式扩展名(.lnk文件名),你首先需要有如下COM对象:WindowsScriptHostObjectModel然后,你可以使用WshShell(或WshShellClass)和IWshShortcut接口来获取快捷方式示例字符串的目标linkPathName=@"D:PicrofoAutobot.lnk";//将此更改为快捷方式路径if(System.IO.File.Exists(linkPathName)){//WshShellClassshell=newWshShellClass();WshShellshell=newWshShell();//新建一个WshShell接口IWshShortcutlink=(IWshShortcut)shell.CreateShortcut(linkPathName);//将界面链接到我们的快捷方式MessageBox.Show(link.TargetPath);//ShowthetargetinaMessageBoxusingIWshShortcut}谢谢,我希望你觉得这有用:)你可以尝试以下步骤将Windows脚本主机对象模型添加到项目中。以上就是C#学习教程:如何从文件快捷方式获取路径名?获取异常分享的所有内容,如果对大家有用还需要了解更多C#学习教程,希望大家多多关注——本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如有转载请注明出处:
