例外可能性の重複取得:
C:\TEMP\
に例えば
Get target of shortcut folderファイルのショートカットからパス名を取得するにはどうすればよいですか?
を、私はショートカットが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
私はそれを解決するために行うshoud?
これは、完全な例外エラーメッセージである:
System.NotImplementedException
が
引っ掛かったメッセージ =メソッドまたは動作が実装されていません。
ソース =GatherLinks
のStackTrace:D:\C-Sharp\GatherLinks\GatherLinks\GatherLinks\Form1.cs
でGatherLinks.Form1.GetShortcutTargetFile(String shortcutFilename)
でShell32.FolderItem.get_GetLink()
で
:GatherLinks.Form1.offlinecrawling
にこのユーザーが最も可能性が高い。このコードは失敗します。その場合にはシンボリックリンク(.LNKのようではないショートカット)を、解決するために求めています。 PInvokeで 'GetFinalPathNameByHandle()'を使う必要があります。サンプルコードはこの[entry here](http://chrisbensen.blogspot.com/2010/06/getfinalpathnamebyhandle.html)にあります。 – ykay