先看效果图:

代码(没什么难度的一个案例,进度条为第三方控件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. SPFILE 、PFILE 的全面解读

    这里先阐述一下数据库的启动过程: 1.      启动实例/例程(nomount状态)时,读取参数文件(文本文件PFILE 或服务器参数文件SPFILE),分配SGA.启动后台进程.打开告警文件及后台 ...

  2. 横瓜从WP7与WP8不兼容之处预测微软公司在未来20年将会倒闭

    横瓜(601069289)  12:40:50 微软频繁升级操作系统版本捞钱,还不向下兼容,其企业的核心竞争力不再是技术,是钱!除了操作系统,其它产品没有任何核心技术和竞争力,微软必死. 横瓜从WP7 ...

  3. 常见缓存算法和LRU的c++实现

    对于web开发而言,缓存必不可少,也是提高性能最常用的方式.无论是浏览器缓存(如果是chrome浏览器,可以通过chrome:://cache查看),还是服务端的缓存(通过memcached或者red ...

  4. Dynamics 365 for Team Members Description

    Dynamics 365 for Team Members, Business edition The Dynamics 365 for Team Members, Business edition ...

  5. 【C语言】字符串模块

    一.字符串简介 * 在Java中,一个字符串可以用String类型来存储 String s = "MJ"; C语言中没有String这种类型.其实字符串就是字符序列,由多个字符组成 ...

  6. Python版C语言词法分析器

    #!/usr/bin/python # -*- coding: utf-8 -*- import sys from Tkinter import * from tkFont import * from ...

  7. 关于Ueditor 前后端分离实现文件上传到独立服务器的问题 望大神们赐教

    最近,由于网站实现多台服务器负载均衡,导致编辑器上传文件需要同步,可是使用同步软件太慢,不太现实,所以想到实现编辑器上传文件直接上传到独立文件服务器.可是没想到遇到坑了. 1.在本地IIS 中添加网站 ...

  8. 关于ABP聚合根类AggregateRoot的思考

    AggregateRoot和Entity的区别 AggregateRoot继承于Entity,并实现了IGeneratesDomainEvents接口 public class AggregateRo ...

  9. selenium自动化过程中遇到的小问题(未完待续)

    1.chrome浏览器调用不起来 代码没出错的情况下,检查下chrome浏览器的版本与chromedriver.exe的版本是否匹配;下面的表格是根据网上及官网整理的chromedriver与chro ...

  10. C#Redis字符串

    上周六通宵打牌周日白天只睡3小时累成狗,从今天起以后不能玩太大的了,小赌怡情大赌伤身,和同事朋友有空玩玩还是好的.今天公司外面马路上有人挂灯笼时死了一个人,哎,快过年了悲剧又发生了,真是生命是脆弱的. ...