资源简介
C#利用Remoting实现服务器与客户端文件的上传与下载
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.IO;
using System.Threading;
namespace Client
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
OpenUrl();
}
long CountLen = 0;
long Len = 0;
Remoteobject.Myobject app;
public void Upload(string filename)
{
if(filename==““)
{
MessageBox.Show(“请选择要上传的文件!““提示“);
return;
}
if(!File.Exists(filename))
{
MessageBox.Show(“上传的文件不存在!““错误“);
return;
}
FileStream fs = new FileStream(filename FileMode.Open);
CountLen=fs.Length;
long Offset =fs.Length/1000;
byte[] byt = new byte[1024*5];
Len = 0;
while (true)
{
int templen = fs.Read(byt 0 byt.Length);
if (templen == 0)
{
MessageBox.Show(“文件写入完成!“);
break;
}
else
{
Len += templen;
int tempvalue=(int)(Len / Offset);
if (tempvalue < 1000)
{
progressBar1.Value = tempvalue;
}
else
{
progressBar1.Value = 1000;
}
button2.Text =“上传中...“+ ((int)(((float)progressBar1.Value / (float)progressBar1.Maximum) * 100)).ToString() + “%“;
label1.Text = “上传:“ + Convert.ToString(Len / 1024) + “K / “ + Convert.ToString(CountLen/1024)+ “K“;
if (!app.Save(Path.GetFileName(filename) byt))
{
MessageBox.Show(“文件写入失败!“);
}
}
}
fs.Close();
fs.Dispose();
}
private void button1_Click(object sender EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
}
}
Thread th;
private void button2_Click(object sender EventArgs e)
{
th = new System.Threading.Thread(new System.Threading.ThreadStart(DoWork));
th.Start();
}
public void DoWork()
{
button1.Enabled = false;
button2.Enabled = false;
button4.Enabled = false;
textBox2.ReadOnly=true;
app.DeleteFile(Path.GetFileName(textBox1.Text));
Upload(textBox1.Text);
button2.Text = “上传“;
textBox2.ReadOnly=false;
button2.Enabled = true;
button1.Enabled = true;
button4.Enabled = true;
CountLen = 0;
Len = 0;
OldLen = 0;
}
long OldLen = 0;
private void timer1_Tick(object sender EventArgs e)
{
float offs = (float)Len / (float)1024 - (float)OldLen / (float)1024;
label2.Text = “当前速度 “ + offs.ToString() + “ K/s“;
OldLen = Len;
if ((int)offs != 0)
{
label6.Text = Convert.ToString((CountLen - Len) / (long)offs) + “s“;
}
}
private void Form1_Load(object sender EventArgs e)
{
timer1.Start();
button1.Enabled=false;
button2.Enabled=false;
button3.Enabled=false;
button4.Enabled=fals
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 28672 2009-07-29 16:37 Remoteob
文件 36352 2009-07-29 16:37 Remoteob
文件 5632 2005-12-08 14:51 Remoteob
文件 16384 2009-07-29 16:33 Remoteob
文件 13824 2009-07-29 16:33 Remoteob
文件 3777 2009-07-29 16:25 Remoteob
文件 6880 2009-07-29 16:37 Remoteob
文件 13154 2009-07-29 16:36 Remoteob
文件 6627 2009-07-29 16:36 Remoteob
文件 329 2009-07-29 16:28 Remoteob
文件 2312 2009-07-29 16:28 Remoteob
文件 6551 2009-07-29 16:28 Remoteob
文件 823 2009-07-29 16:40 Remoteob
文件 899 2009-07-29 16:36 Remoteob
文件 28672 2009-07-29 16:37 Remoteob
文件 180 2009-07-29 16:36 Remoteob
文件 879 2009-07-29 16:33 Remoteob
文件 36352 2009-07-29 16:37 Remoteob
文件 180 2009-07-29 16:33 Remoteob
文件 2570 2009-07-29 16:33 Remoteob
文件 465 2009-06-25 14:27 Remoteob
文件 1160 2009-06-25 14:27 Remoteob
文件 2868 2009-06-25 14:27 Remoteob
文件 5612 2009-06-25 14:27 Remoteob
文件 1091 2009-06-25 14:27 Remoteob
文件 249 2009-06-25 14:27 Remoteob
文件 16384 2009-07-29 16:33 Remoteob
文件 13824 2009-07-29 16:33 Remoteob
文件 4340 2009-07-16 11:44 Remoteob
文件 16384 2009-07-29 16:33 Remoteob
............此处省略45个文件信息
- 上一篇:C#实现MQTT协议
- 下一篇:C#桌面右下角弹出提示窗
相关资源
- C# TIP文件生成和拆解
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
评论
共有 条评论