在ASP.NET中上传文件必须使用FileUpload控件一个个上传吗?

尚方宝剑彤叟无欺 2009-12-01 10:32:51
我的需要是客户端在本地目录中有一组文件需要上传,系统需要对每个文件进行上传,难道要客户一个文件一个文件的选择,然后分别上传吗?那效率太低了吧。有什么办法可以批量上传?各位有办法的帮帮我。
...全文
1133 30 打赏 收藏 转发到动态 举报
写回复
用AI写文章
30 条回复
切换为时间正序
请发表友善的回复…
发表回复
qibie 2009-12-02
  • 打赏
  • 举报
回复
[Quote=引用 28 楼 zcl24 的回复:]
本人测试代码
下载
http://download.csdn.net/source/1862674

C# code<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>SWFUpload Demos- Application Demo</title><link href="css/default.css" rel="stylesheet" type="text/css"/><script type="text/javascript" src="swfupload.js"></script><script type="text/javascript" src="js/handlers.js"></script><script type="text/javascript" src="js/swfupload.queue.js"></script><script type="text/javascript">var swfu;
window.onload= function () {
swfu=new SWFUpload({// Backend Settings upload_url:"upload.aspx",// Relative to the SWF file or absolute post_params: {"PHPSESSID":"<%=Guid.NewGuid().ToString() %>"},

file_size_limit :"2MB",// 2MB file_types :"*.jpg;*.gif;*.png;",
file_types_description :"图片(jpg,gif,png)",
file_upload_limit :100,

custom_settings : {
progressTarget :"fsUploadProgress",
cancelButtonId :"btnCancel"
},// Event Handler Settings - these functions as defined in Handlers.js// The handlers are not part of SWFUpload but are part of my website and control how// my website reacts to the SWFUpload events. file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,// Button Settings button_image_url :"images/XPButtonNoText_65x22.png",// Relative to the SWF file button_placeholder_id :"spanButtonPlaceholder",
button_width:65,
button_height:22,
button_text :'浏览',
button_text_style :'.button { font-family: Helvetica, Arial, sans-serif; font-size: 14pt; } .buttonSmall { font-size: 10pt; }',
button_text_left_padding:18,
button_text_top_padding:1,// Flash Settings flash_url :"swfupload.swf",// Debug Settings debug:false
});
};</script></head><body><div id="content"><form style="clear:both;padding-top:5px;padding-left:15px;" id="subForm"><span id="spanButtonPlaceholder"></span> <input id="startUpload" type="button" value="上传" onclick="imgUpoload()" disabled="disabled" style=" border:0px;width:65px;height:22px;background-image:url(swfupload/images/XPButtonNoText_65x22.png)"/> <input id="btnComplete" type="button" value="完成" onclick="btmComplete()" disabled="disabled" style=" border:0px;width:65px;height:22px;background-image:url(swfupload/images/XPButtonNoText_65x22.png)"/> <input id="btnCancel" type="button" value="取消" onclick="swfu.cancelQueue()" disabled="disabled" style=" border:0px;width:65px;height:22px;background-image:url(swfupload/images/XPButtonNoText_65x22.png)"/></form><divclass="fieldset flash" id="fsUploadProgress"><spanclass="legend">上传列表</span></div><div id="thumbnails"></div></div></body></html>using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.IO;publicpartialclass upload : System.Web.UI.Page
{protectedvoid Page_Load(object sender, EventArgs e)
{//if (this.IsPostBack) {//foreach (HttpPostedFile a in Request.Files)//{// a.SaveAs(Server.MapPath("~/Upload/") + a.FileName);// Response.Write("FILEID:" + a.FileName);//} String fname= Request.Form["Filename"];
FileInfo f=new FileInfo(fname);
fname= Guid.NewGuid()+"."+ f.Extension;
String fullName= Server.MapPath("~/Upload/"+ fname);
Request.Files[0].SaveAs(fullName);
Response.Write("FILEID:"+ fname);//using (FileStream fs = new FileStream(fullName, FileMode.Create, FileAccess.Write))//{// byte[] buffer = new byte[Request.InputStream.Length];// int bts = Request.InputStream.Read(buffer, 0, buffer.Length);// fs.Write(buffer, 0, bts);// fs.Close();// Response.Write("FILEID:" + fname);//} }
}
}using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;publicpartialclass thumbnail : System.Web.UI.Page
{protectedvoid Page_Load(object sender, EventArgs e)
{
String file= Request.QueryString["id"]!=null?"Upload/"+Request.QueryString["id"]:String.Empty;
file= Server.MapPath("~/"+file);if (System.IO.File.Exists(file))
{
Response.WriteFile(file);
}
}
}
[/Quote]

学习了
vip__888 2009-12-01
  • 打赏
  • 举报
回复
模仿QQ相册的功能 批量上传
游北亮 2009-12-01
  • 打赏
  • 举报
回复
好像.net自带也有解压缩的类库了
System.IO.Compression
但是我没用过
songqingpeng2009 2009-12-01
  • 打赏
  • 举报
回复
可以写个批量上传
游北亮 2009-12-01
  • 打赏
  • 举报
回复
上传压缩文件,上传后,在服务器端解压缩
有个类:SharpZipLib
你去搜索一下
quanpp_user 2009-12-01
  • 打赏
  • 举报
回复
http://www.cngr.cn/soft/net/sort0445/2009/2009032037621.html
这个地址就是 你把代码下载下来以后改良一下就可以用了。很方便, 我就那么用的
quanpp_user 2009-12-01
  • 打赏
  • 举报
回复
正好是asp.net用得
quanpp_user 2009-12-01
  • 打赏
  • 举报
回复
不用 你直接上网上下载 flv文件上传。
里面有一个专门上传flv视频文件的控件,是别人先做好的可以批量上传,还可以看到进度条,很实用!
等等 一会我给你找找下载地址
zhaowanru19 2009-12-01
  • 打赏
  • 举报
回复
可以上传多个。。
楼主可以参照校内相册里高级上传。
叶子 2009-12-01
  • 打赏
  • 举报
回复
现在很多网站采用的多附件上传的方式一般是:

1、你添加一个文件,然后点击继续添加,然后再继续添加,最后一起上传。

2、页面一打开就是5个FileUpload 控件,然后可以一次上传1-5个。

如果你要上传多个,也可以去本地文件夹读取你的文件,然后批量上传。
oldleft_hxb 2009-12-01
  • 打赏
  • 举报
回复
可以写个批量上传
guyehanxinlei 2009-12-01
  • 打赏
  • 举报
回复
研究一下WebClient类所提供的方法。
qqzeng-ip 2009-12-01
  • 打赏
  • 举报
回复
edwindoctornma 2009-12-01
  • 打赏
  • 举报
回复
用第三方空间吧,大批量上传附件AspNetUpload,从网上搜一下吧,AspNetUpload.dll
Lovely_baby 2009-12-01
  • 打赏
  • 举报
回复
可以做一个批量上传的控件
JackLeiMM 2009-12-01
  • 打赏
  • 举报
回复
fileupload的.PostedFile .FileName属性都是只读的,那你就读取它好了,把读取出来的路径放入数组中,循环上传到服务器,或者你选择第三方控件
  • 打赏
  • 举报
回复
我试了一下,那个fileupload控件无法设置.PostedFile .FileName属性,是只读的,我如何设置它,以循环上传多个文件?
  • 打赏
  • 举报
回复
需要在页面显示多个FileUplooad控件吗?手工代码创建还是设计时创建?手工代码如何创建?请楼上赐教,谢谢!
tkscascor 2009-12-01
  • 打赏
  • 举报
回复
你也可以用一个的. 你把要上传的文件, 列个清单,把路劲放一个地方存好, 然后循环调用,存入后台就行
加载更多回复(9)

62,254

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧