Copy files to clipboard in C#

前端 未结 2 1323
南旧
南旧 2020-12-01 07:53

I have a Windows Forms TreeView (node, subnodes). Each node contains some additional information in its Tag. Also, each nodes maps a file on the disk. What\'s the easiest wa

2条回答
  •  生来不讨喜
    2020-12-01 08:16

    Consider using the Clipboard class. It features all the methods necessary for putting data on the Windows clipboard and to retrieve data from the Windows clipboard.

    StringCollection paths = new StringCollection();
    paths.Add("f:\\temp\\test.txt");
    paths.Add("f:\\temp\\test2.txt");
    Clipboard.SetFileDropList(paths);
    

    The code above will put the files test.txt and test2.txt for copy on the Windows Clipboard. After executing the code you can navigate to any folder and Paste (Ctrl+V) the files. This is equivalent to selecting both files in Windows Explorer and selecting copy (Ctrl+C).

提交回复
热议问题