问题
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.
回答1:
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
in the first byte:
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 dropEffect = (MemoryStream)aDataDropEffect;
byte[] moveEffect = new byte[4];
dropEffect.Read(moveEffect, 0, moveEffect.Length);
aMove = moveEffect[0] == 2;
}
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
}
来源:https://stackoverflow.com/questions/57787840/paste-files-from-clipboard-with-cut-or-copy