Can the .NET OpenFileDialog be setup to allow the user to select a .lnk file

后端 未结 2 1705
长发绾君心
长发绾君心 2021-01-17 23:48

I want to show a dialog that will allow the user to select a shortcut (.lnk) file. My problem is that the dialog tries to get the file/URL the shortcut is pointing to rather

2条回答
  •  一向
    一向 (楼主)
    2021-01-18 00:20

    The following code returned a .lnk filename for me

      public static string PromptForOpenFilename (Control parent)
      {
         OpenFileDialog dlg = new OpenFileDialog ();
    
         dlg.Filter = "Link (*.lnk)|*.lnk";
         dlg.Multiselect = false;
         dlg.FileName = null;
    
         DialogResult res;
         if (null != parent)
            res = dlg.ShowDialog (parent);
         else
            res = dlg.ShowDialog ();
    
         if (DialogResult.OK == res)
            return dlg.FileName;
         return null;
      }
    

提交回复
热议问题