Currently, most operations on the clipboard on the Internet are only operations on text.,Few operations on files,InCodeprojectI found a solution, but there is still a problem that bothers me (wait a moment, in fact, on the home page is to see if you can help solve it ).
First look at the specificCode:
Cut/copy a file
Void Copytoclipboard ( Bool Cut)
{
String [] Files = Getselection ();
If (Files ! = Null )
{
Idataobject data = New Dataobject (dataformats. filedrop, files );
Memorystream memo = New Memorystream ( 4 );
Byte [] Bytes = New Byte [] {( Byte ) (Cut ? 2 : 5 ), 0 , 0 , 0 };
Memo. Write (bytes, 0 , Bytes. Length );
Data. setdata ( " Preferred dropeffect " , Memo );
Clipboard. setdataobject (data );
}
}
Processing of pasted files:
Processing of pasted files
Private Void Pastemenuitem_click ( Object Sender, system. eventargs E)
{
Idataobject data = Clipboard. getdataobject ();
If ( ! Data. getdatapresent (dataformats. filedrop ))
Return ;
String [] Files = ( String [])
Data. getdata (dataformats. filedrop );
Memorystream stream = (Memorystream)
Data. getdata ( " Preferred dropeffect " , True );
Int Flag = Stream. readbyte ();
If (Flag ! = 2 && Flag ! = 5 )
Return ;
Bool Cut = (Flag = 2 );
Foreach ( String File In Files)
{
String Dest = Homefolder + " \\ " +
Path. getfilename (File );
Try
{
If (CUT)
File. Move (file, DEST );
Else
File. Copy (file, DEST, False );
}
Catch (Ioexception ex)
{
MessageBox. Show ( This , " Failed to perform " +
" Specified operation: \ n " + Ex. Message,
" File operation failed " ,
Messageboxbuttons. OK, messageboxicon. Stop );
}
}
Refreshview ();
}
Note:
1. Set the list of file paths to the clipboard in the array format. Operations on a file must also be performed in array mode.
2. setdata the flag information to the clipboard in a certain format.
ArticleSource: http://www.codeproject.com/KB/shell/Explorer_Drag_Drop.aspx
Related Articles: http://tianmoboping.blog.163.com/blog/static/1573953220087273219414/#comment=fks_082071082082085074080080083095085083086064093083085065
Problem: in Windows Mobile, if a file is cut/copied on a mobile device, nothing is found in the clipboard, and a common Windows file has a path and a flag. The problem now is how to make the PC paste a file if it is cut/copied from the device, because the PC does not recognize it like "\\APplication... "path.