繁体   English   中英

如何在C#拖放操作中分辨文件中的快捷方式?

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

我有一个C#.NET 3.5应用程序,该应用程序已在DataGridView上合并了DragDrop事件。

#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
    }
}

我的问题是,如何区分Windows快捷方式和实际文件? 我试过了:

File.exists(fileName)

在IF块中,这有助于过滤出已拖入的目录,但是快捷方式可以通过。 无论如何,在知道事件名称或通过查询文件系统传递的数据中是否有捷径?

Windows快捷方式是一个文件,扩展名为.lnk。

您能否详细说明您希望使用或不使用它?

如果需要进一步处理快捷方式所针对的文件或文件夹,则可能需要查看此http://www.codeproject.com/KB/dotnet/shelllink.aspx

该项目显示了如何使用Windows Scripting Host操作快捷方式。 例如,在创建运行时可调用包装器(IWshRuntimeLibrary.dll)并将其添加到项目中之后,您可以获取诸如此类的快捷方式的目标。

字符串targetPath;
如果(System.IO.Path.GetExtension(path)==“ .lnk”){
尝试{
IWshRuntimeLibrary.WshShell shell =新的IWshRuntimeLibrary.WshShell();
IWshRuntimeLibrary.IWshShortcut快捷方式=(IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(path);
targetPath = Shortcut.TargetPath;
}
赶上{}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM