PC端到WinCE端文件互相拷贝

本文介绍了一种使用 OpenNETCF.Desktop.Communication 库在 Windows PC 和 Windows Mobile 设备间进行文件传输的方法,并提供了完整的 C# 示例代码。此外,还展示了如何在设备上创建桌面快捷方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


电脑端 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");


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值