/// <summary> /// 获取快捷方式的所在运行目录 /// </summary> /// <param name="srcFileName"></param> /// <returns></returns> public static string GetParentPathOfShortcut(string srcFileName) { ShortCutHelper.IShellLink vShellLink = (ShortCutHelper.IShellLink) new ShortCutHelper.ShellLink(); UCOMIPersistFile vPersistFile = vShellLink as UCOMIPersistFile; vPersistFile.Load(srcFileName, 0); StringBuilder vStringBuilder = new StringBuilder(260); ShortCutHelper.WIN32_FIND_DATA vWIN32_FIND_DATA; vShellLink.GetPath(vStringBuilder, vStringBuilder.Capacity, out vWIN32_FIND_DATA, ShortCutHelper.SLGP_FLAGS.SLGP_RAWPATH); return(vStringBuilder.ToString()); }
private void LbFiles_Drop(object sender, DragEventArgs e) { try { if (GroupInfo != null) { foreach (string fileNameBase in ((System.Array)e.Data.GetData(DataFormats.FileDrop))) { string filePath = fileNameBase; string fileReName = null; if (System.IO.Path.GetExtension(filePath) == ".lnk") { IShellLink vShellLink = (IShellLink) new ShellLink(); UCOMIPersistFile vPersistFile = vShellLink as UCOMIPersistFile; vPersistFile.Load(filePath, 0); StringBuilder vStringBuilder = new StringBuilder(260); WIN32_FIND_DATA vWIN32_FIND_DATA; vShellLink.GetPath(vStringBuilder, vStringBuilder.Capacity, out vWIN32_FIND_DATA, SLGP_FLAGS.SLGP_RAWPATH); filePath = vStringBuilder.ToString(); fileReName = System.IO.Path.GetFileNameWithoutExtension(fileNameBase); } if (Files.Where(t => t.FileFullPath == filePath).Count() == 0) { Files.Add(new ShortcutInfo() { FileFullPath = filePath, FileRename = fileReName, }); } } } } catch (Exception ex) { MessageBoxHelper.ShowErrorMessage(ex); } }