【问题标题】:Detecting file-selection right click in Desktop C#在桌面 C# 中检测文件选择右键单击
【发布时间】:2019-10-24 02:26:28
【问题描述】:

我在文件资源管理器中右键单击文件,但在桌面右键单击时无法获取路径文件或文件夹

public void GetListOfSelectedFilesAndFolderOfWindowsExplorer()
    {
        string filename;
        ArrayList selected = new ArrayList();
        var shell = new Shell32.Shell();
        //For each explorer
        foreach (SHDocVw.InternetExplorer window in new SHDocVw.ShellWindowsClass())
        {
            filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower();
            if (filename.ToLowerInvariant() == "explorer")
            {
                Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
                foreach (Shell32.FolderItem item in items)
                {
                    MessageBox.Show(item.Path.ToString());
                    selected.Add(item.Path);
                }
            }
        }
    }

【问题讨论】:

    标签: c# desktop right-click shell-extensions


    【解决方案1】:

    我通过在 shell 中添加 %1 并在 main 方法中添加代码来解决

    public static void main(string [] args)
      {
        if(args.Length == 1)
        {
           if(args[0] == "/i")
           {
             Console.WriteLine("Parameter i");
           }
        }
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-25
      • 2013-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多