none
Copy and Paste files between Explorer and My Application RRS feed

  • Question

  • Hi All,

    I want to implement following feature in my application:

    1> Select files in Explorer and press Ctrl+C, go to my application UI, click Button1 on my Form, these files are pasted into specified folder

    2> In my application, click Button2, then switch to Explorer, press Ctrl+V to paste specified files into Explorer

    Thanks

    Tuesday, June 14, 2016 1:31 AM

Answers

  • Hi sincos2007,

    >>"Copy and Paste files between Explorer and My Application"

    .NET Framework provides Clipboard class which could place data on and retrieve data from the system Clipboard.

    >>"1> Select files in Explorer and press Ctrl+C, go to my application UI, click Button1 on my Form, these files are pasted into specified folder"

    You could use Clipboard.GetFileDropList() method which is aim to retrieves a collection of file names from the Clipboard. Code below is for your reference.

    var filePaths = Clipboard.GetFileDropList();
    foreach (var filePath in filePaths)
    {
        File.Copy(filePath, @"D:\target\" + Path.GetFileName(filePath));
    }

    >>"2> In my application, click Button2, then switch to Explorer, press Ctrl+V to paste specified files into Explorer"

    You could use Clipboard.SetFileDropList() method which is aim to clear the Clipboard and then add a collection of file names in the FileDrop format. Code below is for your reference.

    StringCollection filePaths = new StringCollection();
    filePaths.Add(@"D:\target\file1.txt");
    filePaths.Add(@"D:\target\file2.txt");
    Clipboard.SetFileDropList(filePaths);
    Best Regards,
    Li Wang

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by sincos2007 Wednesday, June 15, 2016 3:07 AM
    Wednesday, June 15, 2016 1:07 AM
    Moderator