多个文件上传控件

使用:把控件拖到页面中,设置SavePath路径即可上传,如果还要扩展功能请继承此控件。。。

后台代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace WebApplication1
{
public partial class MutiFileUpload : System.Web.UI.UserControl
{
public string SavePath
{
get
{
if (ViewState["SavePath"] == null)
{
ViewState["SavePath"] = Environment.CurrentDirectory;
}
return ViewState["SavePath"].ToString();
}
set
{
if (!Object.Equals(ViewState["SavePath"] , value))
{
ViewState["SavePath"] = value;
}
}
}

protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
if(this.Page.Form!=null)

this.Page.Form.Method = "post";
this.Page.Form.Enctype = "multipart/form-data";
}
int count = Request.Files.Count;
for (int i = 0; i < count; i++)
{
HttpPostedFile file = Request.Files[i];
if (file == null || file.ContentLength <= 0) continue;
file.SaveAs(Path.Combine(SavePath, Path.GetFileName(file.FileName)));
}
}
}
}

前台代码:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MutiFileUpload.ascx.cs" Inherits="WebApplication1.MutiFileUpload" %>
<script type="text/javascript">
function AddFileUpload(o) {
var panel = document.getElementById("fileUploads");
var div = document.createElement("div");
div.innerHtml = "<br/>";
panel.appendChild(div);
var fileUpload = document.createElement("input");
fileUpload.setAttribute("type", "file");
fileUpload.setAttribute("name", Date().toString());
fileUpload.setAttribute("id", Date().toString());
fileUpload.onchange = function() { AddFileUpload(fileUpload); };
if (o.value != null || o.value != "") {
panel.appendChild(fileUpload);
var btnAdd = document.createElement("input");
btnAdd.value = "X";
btnAdd.setAttribute("type", "button");
btnAdd.setAttribute("id", Date().toString());
btnAdd.onclick = function() { RemoveFileUploadByObject(btnAdd, fileUpload); };
panel.appendChild(btnAdd);
}
return fileUpload;
}
function RemoveFileUploadByID(buttonID, fileUploadID) {
var panel = document.getElementById("fileUploads");
var fileUpload = document.getElementById(fileUploadID);
var button = document.getElementById(buttonID);
RemoveFileUploadByObject(button, fileUpload);
}
function RemoveFileUploadByObject(button,fileUpload) {
var panel = document.getElementById("fileUploads");
panel.removeChild(button);
panel.removeChild(fileUpload);
}
function submitFunc() {
document.forms.item(0).submit();
}
window.onload = function() {
// var fileInit = this.parent.document.createElement("input");
// fileInit.setAttribute("type", "file");
// fileInit.setAttribute("id", "initFile");
// fileInit.setAttribute("display", "none");
// this.parent.document.forms.item(0).appendChild(fileInit);
var container = this.document.getElementById("fileUploads");
container.onmousemove = function() {
this.style.cursor = "progress";
}
}
</script>
<p id="fileUploads">
<input type="text" id="AddingFiles" value="AddingFiles"
style=" padding-right:1px; width: 75px;" readonly="readonly" /><input id="Button1" type="button" value="AddFiles" οnclick="AddFileUpload(this);" /></p>
<p>
<input id="Button2" type="submit" value="upload" /></p>

 

转载于:https://www.cnblogs.com/hirisw/archive/2012/10/30/2746015.html

新颖网络上传插件(StorageWebPlug)是一个支持超大文件(2GB,可扩展)上传的COM控件, 具备断点续传,文件MD5验证,大大提高上传效率、节省带宽,有详细的上传进度显示,支持多种脚本语言,欢迎下载体验。免费提供JavaScript SDK包。 产品特点: 1、文件上传使用增强的FTP协议,用户使用浏览器就可以上传超大文件到服务器(支持上传超过1G的文件)。 2、支持断点续传,系统智能续传未上传的文件,续传操作更简单,更方便,更快捷。 3、支持文件批量上传, 一次可以上传多个文件. 上传时有详细的状态显示(包括单个文件进度,整体进度,传输速率,剩余时间等)。 4、新颖网络免费提供JavaScript SDK包。通过新颖网络提供的封装好的JavaScript类库用户可以快速的与现有系统整合。 5、StorageWebPlug提供完善的接口和帮助文档,开发文档。开发人员可以动态设置上传保存路径, 设置允许扩展名, 允许最大大小等,可自定义强。 6、支持各种代理(HTTP, Socket4, Socket5等)。 7、组件采用多线程机制来保证上传效率。 8、支持批量文件上传, 用户可以一次性上传批量文件. 客户端可以绑定HTML表单变量, 服务端并可以接收表单变量 9、服务端文件保存路径可以随意指定,服务端文件保存路径可以灵活变化。保存路径支持网络路径。 10、为提高安全性,服务端组件可以指定用户权限 11、可以限制上传单个文件大小, 控制上传带宽上限, 允许文件扩展名, 拒绝文件扩展名等 12、上传数据时会根据网络状况来控制数据包大小, 避免网络堵塞 13、控件采用ATL编写, cab包只有59KB, 用56k的modem下载不会超过12秒 14、服务端支持Windows 2000 Server/Windows 2003 Server/Windows NT/Windows XP/Unix/Linux等操作系统 15、通过新颖网络业界领先的设计水平打造的操作界面可以帮助您的系统和产品获得更高的品质。 产品介绍:http://www.ncmem.com/service_storagewebplug.aspx 下载地址:http://www.ncmem.com/download.aspx
本实例采用的是Uploadify上传插件,.NET程序,源程序是从网上找的,但是有Bug,已经修改好,并标有部分注释。绝对好用,支持单文件、多文件上传,支持大文件上传,已经过多方面测试,保证好用。 以下附上Uploadify部分常用的参数介绍,要看全部的就去看其API文件了,一般在下载的包里都有。  uploader : uploadify.swf 文件的相对路径,该swf文件是一个带有文字BROWSE的按钮,点击后弹出打开文件对话框,默认值:uploadify.swf。   script : 后台处理程序的相对路径 。默认值:uploadify.php   checkScript :用来判断上传选择的文件在服务器是否存在的后台处理程序的相对路径   fileDataName :设置一个名字,在服务器处理程序中根据该名字来取上传文件的数据。默认为Filedata   method : 提交方式Post 或Get 默认为Post   scriptAccess :flash脚本文件的访问模式,如果在本地测试设置为always,默认值:sameDomain   folder : 上传文件存放的目录 。   queueID : 文件队列的ID,该ID与存放文件队列的div的ID一致。   queueSizeLimit : 当允许多文件生成时,设置选择文件的个数,默认值:999 。   multi : 设置为true时可以上传多个文件。   auto : 设置为true当选择文件后就直接上传了,为false需要点击上传按钮才上传 。   fileDesc : 这个属性值必须设置fileExt属性后才有效,用来设置选择文件对话框中的提示文本,如设置fileDesc为“请选择rar doc pdf文件”,打开文件选择框效果如下图:   fileExt : 设置可以选择的文件的类型,格式如:'*.doc;*.pdf;*.rar' 。   sizeLimit : 上传文件的大小限制 。   simUploadLimit : 允许同时上传的个数 默认值:1 。   buttonText : 浏览按钮的文本,默认值:BROWSE 。   buttonImg : 浏览按钮的图片的路径 。   hideButton : 设置为true则隐藏浏览按钮的图片 。   rollover : 值为true和false,设置为true时当鼠标移到浏览按钮上时有反转效果。   width : 设置浏览按钮的宽度 ,默认值:110。   height : 设置浏览按钮的高度 ,默认值:30。   wmode : 设置该项为transparent 可以使浏览按钮的flash背景文件透明,并且flash文件会被置为页面的最高层。 默认值:opaque 。   cancelImg :选择文件到文件队列中后的每一个文件上的关闭按钮图标 Uploadify还自带了很多参数及有用的方法和回调函数,都在API里,虽然是全英文的,但很容易看懂,这里就不说了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值