[英]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.