先看效果图:

代码(没什么难度的一个案例,进度条为第三方控件ProgressODoom.dll,自己去网上下。)

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 System.IO;
using System.Collections;
using System.Threading; namespace VideoTrans
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
LoadListView();
this.FormClosed += (sender, e) => {
Application.Exit();
System.Diagnostics.Process pro = System.Diagnostics.Process.GetCurrentProcess();
pro.Kill();
};
}
/// <summary>
/// 初始化上传列表
/// </summary>
void LoadListView()
{
listView1.View = View.Details;
listView1.CheckBoxes = true;
listView1.GridLines = true;
listView1.Columns.Add("文件名",,HorizontalAlignment.Center);
listView1.Columns.Add("文件大小", , HorizontalAlignment.Center);
listView1.Columns.Add("文件路径", , HorizontalAlignment.Center);
}
/// <summary>
/// 存储目录
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if(fbd.ShowDialog()==DialogResult.OK)
{
textBox1.Text=fbd.SelectedPath;
}
}
/// <summary>
/// 打开上传文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, EventArgs e)
{ OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
if(ofd.ShowDialog()==DialogResult.OK)
{
foreach(string filename in ofd.FileNames)
{
FileInfo fi=new FileInfo(filename);
ListViewItem lvi = new ListViewItem(Path.GetFileNameWithoutExtension(filename));
lvi.Tag = filename;
lvi.SubItems.Add(fi.Length.ToString());
//lvi.SubItems.Add((fi.Length / (1024 * 1024)).ToString() + "M");
lvi.SubItems.Add(Path.GetDirectoryName(filename));
listView1.Items.Add(lvi);
} }
}
public delegate void DeleFile(int position);
/// <summary>
/// 文件上传
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{ if (textBox1.Text.Trim().Equals(""))
{
MessageBox.Show("请先选择存储目录..!");
}
else
{ if (listView1.Items.Count > )
{
int j = ;
string count = listView1.CheckedItems.Count.ToString();
for (int i = ; i < listView1.Items.Count;i++ )
{ if (listView1.Items[i].Checked)
{
j++;
string fileName = Path.GetFileName(listView1.Items[i].Tag.ToString());
label1.Text = string.Format("正在上传文件:[{0}]", listView1.Items[i].Text) + ":" + j.ToString() + ":" + count;
FileStream des = new FileStream(Path.Combine(textBox1.Text, fileName), FileMode.OpenOrCreate, FileAccess.Write);
FileStream fir = new FileStream(listView1.Items[i].Tag.ToString(), FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[];
int size = ; int ren = ;
while (ren < fir.Length)
{
Application.DoEvents();
size = fir.Read(buffer,,buffer.Length);
des.Write(buffer, , size);
ren += size;
Pro(ren);
}
listView1.Items[i].Checked = false;
}
else
{
continue;
}
}
//MessageBox.Show("上传成功!");
}
else
{
return;
}
} }
public void Pro(int copy)
{ if (this.progressBarEx1.InvokeRequired)
{
this.progressBarEx1.Invoke(new DeleFile(Pro),new object[]{copy});
return;
}
foreach (ListViewItem lvi in listView1.CheckedItems)
{
string total = lvi.SubItems[].Text;
int pro = (int)((float)copy / long.Parse(total) * );
if (pro <= progressBarEx1.Maximum)
{
progressBarEx1.Value = pro;
progressBarEx1.Text = label1.Text.Split(':')[].ToString() + Environment.NewLine + string.Format("上传进度:{0}%", pro) + Environment.NewLine + string.Format("已上传文件数:{0}/{1}", label1.Text.Split(':')[].ToString(), label1.Text.Split(':')[].ToString()); }
} }
/// <summary>
/// 删除文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button4_Click(object sender, EventArgs e)
{
foreach(ListViewItem lvi in listView1.CheckedItems)
{
lvi.Remove();
}
} }
}

转自:http://blog.csdn.net/wanlong360599336/article/details/7564508

【.NET】转载:使用FileStream批量上传文件。的更多相关文章

  1. Linux命令之rz - 批量上传文件,简单易用(转载)

    用途说明 rz命令能够批量上传文件,当然也可上传单个文件啦.使用的协议是古老的ZMODEM协议,尽管协议古老,但毫不影响的简单易用的特性.一般情 况我们要上传文件到Linux系统,要么使用ftp(还得 ...

  2. 转 Android网络编程之使用HttpClient批量上传文件 MultipartEntityBuilder

    请尊重他人的劳动成果,转载请注明出处:Android网络编程之使用HttpClient批量上传文件 http://www.tuicool.com/articles/Y7reYb 我曾在<Andr ...

  3. 使用 sendKeys(keysToSend) 批量上传文件

    未经允许,禁止转载!!! 在selenium里面处理文件上传的时候可以使用sendKeys(keysToSend) 上传文件 例如: element.sendKeys(“C:\\test\\uploa ...

  4. 不带插件 ,自己写js,实现批量上传文件及进度显示

    今天接受项目中要完成文件批量上传文件而且还要显示上传进度,一开始觉得这个应该不是很麻烦,当我在做的时候遇到了很多问题,很头疼啊. 不过看了别人写的代码,自己也测试过,发现网上好多都存在一些问题,并不是 ...

  5. Python基于Python实现批量上传文件或目录到不同的Linux服务器

    基于Python实现批量上传文件或目录到不同的Linux服务器   by:授客 QQ:1033553122 实现功能 1 测试环境 1 使用方法 1 1. 编辑配置文件conf/rootpath_fo ...

  6. input file multiple 批量上传文件

    这几天维护系统,有一个批量上传文件功能,出现了一点小问题 我的笔记本选择要上传的文件很正常 但在测试环境上,别人的电脑上,选择上传文件之后 一开始,以为是代码问题,网上找了很多的资料,但还是没用,然后 ...

  7. TP3.2批量上传文件(图片),解决同名冲突问题

    1.html <form action="{:U('Upload/index')}" enctype="multipart/form-data" meth ...

  8. 用Azure CLI批量上传文件

    在Windows环境下,我们可以使用AzCopy批量上传文件.其效率和传输速率都是非常快的. 在Linux或MacOS环境下,可以使用Azure的CLI实现批量文件的上传. 下面的脚本可以实现此功能. ...

  9. Java Miniui实现批量上传文件demo 201906221520

    可能需要的jar包: 需要miniui(类似easyui). Test2019062201.jsp <%@ page language="java" contentType= ...

随机推荐

  1. twemproxy接收流程探索——twemproxy代码分析正编

    在这篇文章开始前,大家要做好一个小小的心理准备,由于twemproxy代码是一份优秀的c语言,为此,在twemproxy的代码中会大篇幅使用c指针.但是不论是普通类型的指针还是函数指针,都可以让我们这 ...

  2. headfirst设计模式(1)—策略模式

    什么是策略模式 策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们还可以相互替换.策略模式让算法独立于使用它的客户而独立变化(摘自百度百科) 关键字:算法封装,相互替换,独立变化 算法封装 ...

  3. 回溯法、数独与N阶可达问题

    回溯法是剪了枝的穷举,这是字面上的说法,不太好理解,不如讲解实例来的酸爽,于是引出了N阶可达问题: 有N个国家,每个国家有若干城市,小明要从中国(任意一个城市)出发,遍历所有国家(假设这个遍历顺序已经 ...

  4. MVC源码分析 - 路由匹配

    上一篇 说到了路由事件注册以及路由表的生成, 前面 也解析到了, 管道事件的建立, 那么接下来, 肯定就是要调用执行这些事件了, 这些就不表了, 我已经得到我想要的部分了, 接下来, 在执行这些管道事 ...

  5. python绝技 — 侦听802.11 Probe请求

    代码 #!/usr/bin/python #--*--coding=utf-8--*-- from scapy.all import * interface = 'wlan1' probeReqs = ...

  6. js的eval函数解析后台返回的json数据时为什加上圆括号eval("("+data+")"),而HTML页面定义的数据不用

    一,情况如下,这是成功代码: $(function () { $.ajax({ url: "Demo.aspx", type: "post", data: { ...

  7. python爬虫---python3.5---eclipse

    解析中文会出现\xbe\c8\90\hd........ 这个和你的编码选择有关.如果是解析成html,则需 fout = open('output.html', 'w',encoding='utf- ...

  8. linux的基本命令

    find: find [路径] [选项] [查找规则] [动作] -print 打印出找到的文件,以\n结束 -print0 打印出找到的文件,无换行 -exec command 对找到的文件执行命令 ...

  9. 加班计时App

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. Java中不定参的使用规则

    Java中有时候会使用到不定参数,它的使用规则有2项: 一个方法中只能使用一个不定参数. 不定参数必须是方法中最后一个参数. 不定参数在传入的过程中会行成一个数组传入,如果不会放在最后一个,虚拟机无法 ...