How can I tell a shortcut from a file in a C# drag and drop operation?


I have a C# .NET 3.5 app that I have incorporated the DragDrop event on a DataGridView.

#region File Browser - Drag and Drop Ops private void dataGridView_fileListing_DragDrop(object sender, DragEventArgs e) { string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[]; foreach (string fileName in fileList) { //logic goes here } }

My question is, how can I differentiate a windows shortcut from an actual file? I tried:


in an IF block which is useful to filter out directories that have been dragged in, however shortcuts get through. Is there anyway on to tell a shortcut in the data passed in by the event data, or by querying the file system once I have the name?


A Windows shortcut is a file, just with a .lnk extension.

Could you elaborate more about what you hope to do or not do with it?


If you need to go further and process the files or folders the shortcut is targeting, you might want to look at this <a href="http://www.codeproject.com/KB/dotnet/shelllink.aspx" rel="nofollow">http://www.codeproject.com/KB/dotnet/shelllink.aspx</a>.

The project shows how to use Windows Scripting Host to manipulate shortcuts. For example, after creating a runtime callable wrapper (IWshRuntimeLibrary.dll) and adding this to your project, you can get the target of the shortcuts like this...

string targetPath;<br /> if (System.IO.Path.GetExtension(path) == ".lnk"){<br /> try{<br /> IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();<br /> IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(path);<br /> targetPath = shortcut.TargetPath;<br /> }<br /> catch { }<br /> }


  • c# drag drop DataObject
  • Multiple events with Drag and Drop inside my ListView
  • Implement file dragging to the desktop from a .net winforms application?
  • Save file to device with memorystream
  • Drag and drop using a class method
  • Export FlowDocument with UIElement to rtf
  • Drag and drop not working in C#
  • how to make two bars in the same fig Matlab
  • Sending PictureBox Contents to MsPaint
  • beforeunload event during window close Vs meteor-auto-reload
  • XNA Number lock affects input
  • Getting rollback in creating shortcuts on installation of node js in windows 7
  • Symfony2 Form is always empty after submitting
  • how do i know how many clients are calling my WCF service function
  • Colorize knockoutjs comment bindings in code editor
  • Which JQuery document.ready is better? [duplicate]
  • Add the % on tab when working with HAML on vim
  • Serializing a list of Object using Json.NET
  • c# How to detect and process a .URL file type on DragDrop event
  • RxJava,Retrofit Error :Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
  • Intellij Idea Terminal shortcut not working
  • How to Translate texts contained in MsgBox in Inno Setup?
  • Are there any side effects from calling SQLAlchemy flush() within code?
  • PLSQL: Get number of records updated vs inserted when a merge statement is used
  • RxJava debounce by arbitrary value
  • onBackPressed() not being executed
  • Content-Length header not returned from Pylons response
  • Combining SpatialPolygonsDataFrame of two neighbour countries
  • Ajax Loaded meta Tags
  • Xamarin Forms - UWP Fonts
  • C# - Serializing and deserializing static member
  • Sony Xperia Z Tablet not found by adb
  • script to move all files from one location to another location
  • Javascript convert timezone issue
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • ActionScript 2 vs ActionScript 3 performance
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Arrays break string types in Julia
  • How do you join a server to an Active Directory (domain)?
  • Why joiner is not used after Sequence generator or Update statergy