重複の可能性:
ショートカット フォルダーのターゲットを取得
たとえば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
StackTrace :
atShell32.FolderItem.get_GetLink()
atGatherLinks.Form1.GetShortcutTargetFile(String shortcutFilename)
in
D:\C-Sharp\GatherLinks\GatherLinks\GatherLinks\Form1.cs
:line
904
atGatherLinks.Form1.offlinecrawling