Clipboard cut/copy and paste file + 1 problem to be solved

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.