Click here to Skip to main content
15,614,257 members
Please Sign up or sign in to vote.
1.22/5 (3 votes)
See more:
I can get list of files from clipboard but i cant detect whether this data is for moving or copy?

when user click on both "cut" and "paste" option data is set into clipboard and we can retrieve it using some code but how we can simultaneously get whether this clipboard data is for copy or cut?

What I have tried:

I can get list of files from clipboard using this code:
IDataObject data = Clipboard.GetDataObject();
if (!data.GetDataPresent(DataFormats.FileDrop))
string[] clipboardData = (string[])data.GetData(DataFormats.FileDrop);
Updated 6-Sep-22 2:28am
RickZeeland 8-Apr-16 16:34pm    
Did you downvote solution 1 and 2 ?

No way. And you never need it. First of all, there is no such distinction. The question simply makes no sense.

Let me also explain that: there is no such thing as "clipboard move". This is a pure application-side part. You just missed the idea. Yes, some applications offer "cut file — past file" operations which is functionally equivalent to "move", but this is nothing but a metaphor. In the OS, there is no such thing.

One example is "moving files". This is how it works: first, application handles "cut files" command and simply mark some files scheduled for the move. It's important to understand that nothing is cut. Next command is supposed to be "paste files". If it is issued before any other clipboard operation, the files are simply moved. If the user does something else, the "cut" command is simply ignored; and the files stay where they were. If the user issues that command, the files are moved. Same things happen to the cells of a spreadsheet, including Excel.

You can develop the same technique in your application. The question is: is the system clipboard even involved? The answer is: yes and no. As in both examples explained in the previous paragraph, your application can be executed in one instance, of several instances of the application process. If it was always the same instance, using the clipboard would be pointless. But the same application can be executed in several different processes; and the processes are isolated. They need to communicate on this file copy/paste/move activity; and this is conveniently done via the available system clipboard. All you need to implement similar thing is little logical reasoning.

Moreover, as to the file manipulation: you can have multiple unrelated application using Shell API. Not only they are different processes, but even the processes of different applications. And they can communicate through the system clipboard, in this aspect.

That's all.

Share this answer
This is not possible with Clipboard, it's determined by the application that uses Clipboard. Sorry !
Share this answer
When you use file drop, you just check the shift and control keys:
if ((ModifierKeys & Keys.Shift) != 0)
    // It's a move operation.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900