Reputation: 687
The .NET Clipboard class has methods to put files into the clipboard and also define if they should be moved or copied (cut/copy).
But if I want to paste files that were copied into the clipboard, I see no way to find out if the file was cut or copied with standard Clipboard methods.
Upvotes: 7
Views: 1863
Reputation: 687
The information is stored in a Clipboard data object named "Preferred DropEffect".
A memory stream containing a 4-byte-array contains the enum value for System.Windows.DragDropEffects
:
public static void PasteFilesFromClipboard(string aTargetFolder)
{
var aFileDropList = Clipboard.GetFileDropList();
if (aFileDropList == null || aFileDropList.Count == 0) return;
bool aMove = false;
var aDataDropEffect = Clipboard.GetData("Preferred DropEffect");
if (aDataDropEffect != null)
{
MemoryStream aDropEffect = (MemoryStream)aDataDropEffect;
byte[] aMoveEffect = new byte[4];
aDropEffect.Read(aMoveEffect, 0, aMoveEffect.Length);
var aDragDropEffects = (DragDropEffects)BitConverter.ToInt32(aMoveEffect, 0);
aMove = aDragDropEffects.HasFlag(DragDropEffects.Move);
}
foreach (string aFileName in aFileDropList)
{
if (aMove) { } // Move File ...
else { } // Copy File ...
}
}
[Flags]
public enum DragDropEffects
{
Scroll = int.MinValue,
All = -2147483645,
None = 0,
Copy = 1,
Move = 2,
Link = 4
}
Upvotes: 9