:
C:\TEMP\
में
Get target of shortcut folderमुझे फ़ाइल शॉर्टकट से पथ का नाम कैसे प्राप्त होगा? अपवाद संभव डुप्लिकेट हो रही
उदाहरण के लिए, मैं एक शॉर्टकट test.dll
कहा जाता है शॉर्टकट फ़ाइल नाम test.dll
मैं प्राप्त करना चाहते हैं के लिए नेतृत्व करेंगे शॉर्टकट से केवल पथ का नाम स्वयं फ़ाइल में। तो, मैं इस फ़ंक्शन को एक और रिकर्सिव फ़ंक्शन में कॉल कर रहा हूं और इस हार्ड फ़ंक्शन में प्रत्येक बार एक और निर्देशिका डालता हूं।
उदाहरण के लिए, पहली निर्देशिका C:\TEMP
है तो C:\TEMP
में शॉर्टकट फ़ाइल है जिसे मैं केवल फ़ाइल में पथ प्राप्त करना चाहता हूं। Shortcut
(C:\TEMP\hpwmdl23.dat
)
तो, मैं क्या प्राप्त करना चाहते है -
hpwmdl23.dat
hpwins23.dat
hpwmdl23.dat: परीक्षण के लिएC:\TEMP
में मैं अब 3 फ़ाइलें \ 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: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