电脑端 Windows Mobile 设备中心必须可以连接到手持设备
首先需要引用 OpenNETCF.Desktop.Communication
源代码下载地址如下 https://social.msdn.microsoft.com/Forums/en-US/8344cb0d-3891-4eab-a62b-4af5a7ee32ad/c-opennetcf-copyfiletodevice-copyfilefromdevice-windows-7-wmdc?forum=netfxcompact
测试程序界面如下,在拷贝前需要先点击连接。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenNETCF.Desktop.Communication;
namespace CopyFileToWinCE
{
public partial class Form1 : Form
{
RAPI myrapi = new RAPI ();
public Form1()
{
InitializeComponent();
}
private void btnConnect_Click(object sender, EventArgs e)
{
myrapi.Connect();
while (!myrapi.DevicePresent)
{
MessageBox.Show("Please connect your device to your PC using ActiveSync and before clicking the OK button.",
"No Device Present");
myrapi.Connect();
}
}
private void btnCopyFile_Click(object sender, EventArgs e)
{
try
{
if ((txtCopySource.Text == "") || (txtCopyDestination.Text == ""))
{
MessageBox.Show("You must provide both a source and destination file.",
"Missing File Information");
}
else
{
switch (cmbCopyDirection.Text)
{
case "": MessageBox.Show("You must select a direction before initiating the copy.", "No Destination Selected");
break;
case "from desktop to device": myrapi.CopyFileToDevice(txtCopySource.Text, txtCopyDestination.Text);
MessageBox.Show("Your file has been copied.", "Copy Success");
break;
case "from device to desktop":
myrapi.CopyFileFromDevice(txtCopySource.Text, txtCopyDestination.Text);
MessageBox.Show("Your file has been copied.", "Copy Success");
break;
}
}
}
catch (Exception ex)
{
MessageBox.Show("The following error occurred copying the file -" + ex.Message, "Copy Error");
}
}
}
}
为程序创建桌面快捷方式 myrapi.CreateDeviceShortcut(@"\Windows\桌面\扫描系统3190.lnk", @"Platform\ScanBarcode\3190\ScanBarcode3190.exe");
myrapi.CreateDeviceShortcut(@"\Windows\桌面\无线扫描系统W3190.lnk", @"Platform\ScanBarcode\W3190\ScanBarcodeW3190.exe");