asp .net 多文件上传(二)

摘要:
=null)&&(form.Enctype.Length==0))71{72form.Enctype="multipart/form-data";73}74}75protectedoverridevoidRender(HtmlTextWriterwriter)76{77base.Render(writer);78writer.Write("");79writer.Write(strTable);80}8182WriteTable#regionWriteTable83privatereadonlystringstrTable=@"8485868788899091 92 949596979899100101102";103#endregion104script#regionscript105privatereadonlystringstrScript=@"106˂!--107varcount=1;108varSelectControlID='SelectListBox';109functionaddFile()110{111112if(!');134returnfalse;135}136filenames[i].style.display='no

在上篇asp .net 多文档上传控件实现的多文件上载控件,在上载文件太大的时候,就会出现“文件已经关闭”的错误,现在这个版本,重新实现修改原来的方式,可以上载任意大小的文件,并且在添加文件时也不用回调服务端,删除文件时,也会动态的删除选择的文件,截图如下:

选择文件:

image

上载成功:

image

源码

asp .net 多文件上传(二)第3张{
16asp .net 多文件上传(二)第4张publicclassMutiLoad:WebControl
17asp .net 多文件上传(二)第5张asp .net 多文件上传(二)第6张asp .net 多文件上传(二)第3张{
18asp .net 多文件上传(二)第4张stringstrFiles="";
19asp .net 多文件上传(二)第4张List<int>list=newList<int>();
20asp .net 多文件上传(二)第4张
21asp .net 多文件上传(二)第4张publicintCount
22asp .net 多文件上传(二)第5张asp .net 多文件上传(二)第6张asp .net 多文件上传(二)第3张{
23asp .net 多文件上传(二)第4张get24asp .net 多文件上传(二)第5张asp .net 多文件上传(二)第6张asp .net 多文件上传(二)第3张{
25asp .net 多文件上传(二)第4张
26asp .net 多文件上传(二)第4张returnlist.Count;
27asp .net 多文件上传(二)第21张}
28asp .net 多文件上传(二)第21张}
29asp .net 多文件上传(二)第4张publicint[]FileIndex
30asp .net 多文件上传(二)第5张asp .net 多文件上传(二)第6张asp .net 多文件上传(二)第3张{
31asp .net 多文件上传(二)第4张get32asp .net 多文件上传(二)第5张asp .net 多文件上传(二)第6张asp .net 多文件上传(二)第3张{
33asp .net 多文件上传(二)第4张returnlist.ToArray();
34asp .net 多文件上传(二)第21张}
35asp .net 多文件上传(二)第21张}
36asp .net 多文件上传(二)第4张protectedoverridevoidOnLoad(EventArgse)
37asp .net 多文件上传(二)第5张asp .net 多文件上传(二)第6张asp .net 多文件上传(二)第3张{
38asp .net 多文件上传(二)第4张base.OnLoad(e);
39asp .net 多文件上传(二)第4张if(Page.IsPostBack)
40asp .net 多文件上传(二)第5张asp .net 多文件上传(二)第6张asp .net 多文件上传(二)第3张{
41asp .net 多文件上传(二)第4张if(Page.Request.Form["hidvalue"]==null)
42asp .net 多文件上传(二)第4张strFiles="";
43asp .net 多文件上传(二)第4张else44asp .net 多文件上传(二)第4张strFiles=","+Page.Request.Form["hidvalue"].Trim(',')+",";
45asp .net 多文件上传(二)第4张HttpFileCollectionfiles1=HttpContext.Current.Request.Files;
46asp .net 多文件上传(二)第4张for(inti=0;i<files1.Count;i++)
47asp .net 多文件上传(二)第5张asp .net 多文件上传(二)第6张asp .net 多文件上传(二)第3张{
48asp .net 多文件上传(二)第4张if(CheckFile(files1[i].FileName))
49asp .net 多文件上传(二)第4张list.Add(i);
50asp .net 多文件上传(二)第21张}
51asp .net 多文件上传(二)第4张
52asp .net 多文件上传(二)第21张}
53asp .net 多文件上传(二)第21张}
54asp .net 多文件上传(二)第4张privateboolCheckFile(stringFileName)
55asp .net 多文件上传(二)第5张asp .net 多文件上传(二)第6张asp .net 多文件上传(二)第3张{
56asp .net 多文件上传(二)第4张if(strFiles.IndexOf(","+FileName+",")==-1)
57asp .net 多文件上传(二)第4张returnfalse;
58asp .net 多文件上传(二)第4张strFiles=strFiles.Replace(FileName+",","");
59asp .net 多文件上传(二)第4张returntrue;
60asp .net 多文件上传(二)第21张}
61asp .net 多文件上传(二)第4张protectedoverridevoidOnPreRender(EventArgse)
62asp .net 多文件上传(二)第5张asp .net 多文件上传(二)第6张asp .net 多文件上传(二)第3张{
63asp .net 多文件上传(二)第4张if(!Page.ClientScript.IsClientScriptBlockRegistered("MyJavaScript"))
64asp .net 多文件上传(二)第5张asp .net 多文件上传(二)第6张asp .net 多文件上传(二)第3张{
65asp .net 多文件上传(二)第4张Page.ClientScript.RegisterClientScriptBlock
66asp .net 多文件上传(二)第4张(Page.GetType(),"MyJavaScript",strScript);
67asp .net 多文件上传(二)第21张}
68asp .net 多文件上传(二)第4张base.OnPreRender(e);
69asp .net 多文件上传(二)第4张HtmlFormform=this.Page.Form;
70asp .net 多文件上传(二)第4张if((form!=null)&&(form.Enctype.Length==0))
71asp .net 多文件上传(二)第5张asp .net 多文件上传(二)第6张asp .net 多文件上传(二)第3张{
72asp .net 多文件上传(二)第4张form.Enctype="multipart/form-data";
73asp .net 多文件上传(二)第21张}
74asp .net 多文件上传(二)第21张}
75asp .net 多文件上传(二)第4张protectedoverridevoidRender(HtmlTextWriterwriter)
76asp .net 多文件上传(二)第5张asp .net 多文件上传(二)第6张asp .net 多文件上传(二)第3张{
77asp .net 多文件上传(二)第4张base.Render(writer);
78asp .net 多文件上传(二)第4张writer.Write("<inputtype='hidden'id='hidvalue'name='hidvalue'/>");
79asp .net 多文件上传(二)第4张writer.Write(strTable);
80asp .net 多文件上传(二)第21张}
81asp .net 多文件上传(二)第4张
82asp .net 多文件上传(二)第96张asp .net 多文件上传(二)第97张WriteTable#regionWriteTable83asp .net 多文件上传(二)第4张privatereadonlystringstrTable=@"<tableborder='0'cellpadding='0'cellspacing='0'width='100%'>
84asp .net 多文件上传(二)第4张<tr>
85asp .net 多文件上传(二)第4张<td>
86asp .net 多文件上传(二)第4张<pid='MyFile'>
87asp .net 多文件上传(二)第4张<spannum='1'>
88asp .net 多文件上传(二)第4张<inputtype='file'size='60'name='File'style='100%;height:25px'/></span></p>
89asp .net 多文件上传(二)第4张</td>
90asp .net 多文件上传(二)第4张<tdalign='left'style='100px'>
91asp .net 多文件上传(二)第4张&nbsp;<inputtype='button'value='增加'onclick='addFile()'/>
92asp .net 多文件上传(二)第4张<inputtype='button'value='删除'
93asp .net 多文件上传(二)第4张onclick='javascript:removeOptionSelected()'/>&nbsp;
94asp .net 多文件上传(二)第4张</td>
95asp .net 多文件上传(二)第4张</tr>
96asp .net 多文件上传(二)第4张<tr>
97asp .net 多文件上传(二)第4张<tdcolspan='2'align='left'>
98asp .net 多文件上传(二)第4张<selectsize='10'name='SelectListBox'id='SelectListBox'style='100%'>
99asp .net 多文件上传(二)第4张</select>
100asp .net 多文件上传(二)第4张</td>
101asp .net 多文件上传(二)第4张</tr>
102asp .net 多文件上传(二)第4张</table>";
103asp .net 多文件上传(二)第21张#endregion
104asp .net 多文件上传(二)第96张asp .net 多文件上传(二)第97张script#regionscript105asp .net 多文件上传(二)第4张privatereadonlystringstrScript=@"<scriptlanguage='JavaScript'type='text/javascript'>
106asp .net 多文件上传(二)第4张<!--
107asp .net 多文件上传(二)第4张varcount=1;
108asp .net 多文件上传(二)第4张varSelectControlID='SelectListBox';
109asp .net 多文件上传(二)第4张functionaddFile()
110asp .net 多文件上传(二)第4张{
111asp .net 多文件上传(二)第4张
112asp .net 多文件上传(二)第4张if(!CheckFile())
113asp .net 多文件上传(二)第4张return;
114asp .net 多文件上传(二)第4张count++;
115asp .net 多文件上传(二)第4张varstr=""<spanNum='""+count+""'><INPUTtype='file'size='60'NAME='File' /></span>"";
116asp .net 多文件上传(二)第4张document.getElementById('MyFile').insertAdjacentHTML('beforeEnd',str)
117asp .net 多文件上传(二)第4张}
118asp .net 多文件上传(二)第4张functionCheckFile()
119asp .net 多文件上传(二)第4张{
120asp .net 多文件上传(二)第4张varfilenames=document.getElementById('MyFile').getElementsByTagName('span');
121asp .net 多文件上传(二)第4张for(vari=0;i<filenames.length;i++)
122asp .net 多文件上传(二)第4张{
123asp .net 多文件上传(二)第4张if(filenames[i].getAttribute('Num')==count)
124asp .net 多文件上传(二)第4张{
125asp .net 多文件上传(二)第4张varfile=filenames[i].getElementsByTagName('input').item(0).value;
126asp .net 多文件上传(二)第4张if(file=='')
127asp .net 多文件上传(二)第4张{
128asp .net 多文件上传(二)第4张alert('请选择文件');
129asp .net 多文件上传(二)第4张returnfalse;
130asp .net 多文件上传(二)第4张}
131asp .net 多文件上传(二)第4张if(CheckOption(file))
132asp .net 多文件上传(二)第4张{
133asp .net 多文件上传(二)第4张alert('文件已经在列表中存在。');
134asp .net 多文件上传(二)第4张returnfalse;
135asp .net 多文件上传(二)第4张}
136asp .net 多文件上传(二)第4张filenames[i].style.display='none';
137asp .net 多文件上传(二)第4张appendOptionLast(file);
138asp .net 多文件上传(二)第4张returntrue;
139asp .net 多文件上传(二)第4张}
140asp .net 多文件上传(二)第4张
141asp .net 多文件上传(二)第4张}
142asp .net 多文件上传(二)第4张returntrue;
143asp .net 多文件上传(二)第4张}
144asp .net 多文件上传(二)第4张functionCheckUpload()
145asp .net 多文件上传(二)第4张{
146asp .net 多文件上传(二)第4张varstr=getOption();
147asp .net 多文件上传(二)第4张if(str=='')
148asp .net 多文件上传(二)第4张{
149asp .net 多文件上传(二)第4张alert('请选择要上载的文件。');
150asp .net 多文件上传(二)第4张returnfalse;
151asp .net 多文件上传(二)第4张}
152asp .net 多文件上传(二)第4张document.all.hidvalue.value=str;
153asp .net 多文件上传(二)第4张returntrue;
154asp .net 多文件上传(二)第4张}
155asp .net 多文件上传(二)第4张
156asp .net 多文件上传(二)第4张
157asp .net 多文件上传(二)第4张functioninsertOptionBefore(num)
158asp .net 多文件上传(二)第4张{
159asp .net 多文件上传(二)第4张varelSel=document.getElementById(SelectControlID);
160asp .net 多文件上传(二)第4张if(elSel.selectedIndex>=0){
161asp .net 多文件上传(二)第4张varelOptNew=document.createElement('option');
162asp .net 多文件上传(二)第4张elOptNew.text=num;
163asp .net 多文件上传(二)第4张elOptNew.value=num;
164asp .net 多文件上传(二)第4张varelOptOld=elSel.options[elSel.selectedIndex];
165asp .net 多文件上传(二)第4张try{
166asp .net 多文件上传(二)第4张elSel.add(elOptNew,elOptOld);//standardscompliant;doesn'tworkinIE
167asp .net 多文件上传(二)第4张}
168asp .net 多文件上传(二)第4张catch(ex){
169asp .net 多文件上传(二)第4张elSel.add(elOptNew,elSel.selectedIndex);//IEonly
170asp .net 多文件上传(二)第4张}
171asp .net 多文件上传(二)第4张}
172asp .net 多文件上传(二)第4张}
173asp .net 多文件上传(二)第4张
174asp .net 多文件上传(二)第4张functionremoveOptionSelected()
175asp .net 多文件上传(二)第4张{
176asp .net 多文件上传(二)第4张varelSel=document.getElementById(SelectControlID);
177asp .net 多文件上传(二)第4张vari;
178asp .net 多文件上传(二)第4张for(i=elSel.length-1;i>=0;i--){
179asp .net 多文件上传(二)第4张if(elSel.options[i].selected){
180asp .net 多文件上传(二)第4张elSel.remove(i);
181asp .net 多文件上传(二)第4张}
182asp .net 多文件上传(二)第4张}
183asp .net 多文件上传(二)第4张}
184asp .net 多文件上传(二)第4张
185asp .net 多文件上传(二)第4张functionappendOptionLast(num)
186asp .net 多文件上传(二)第4张{
187asp .net 多文件上传(二)第4张varelOptNew=document.createElement('option');
188asp .net 多文件上传(二)第4张elOptNew.text=num;
189asp .net 多文件上传(二)第4张elOptNew.value=num;
190asp .net 多文件上传(二)第4张varelSel=document.getElementById(SelectControlID);
191asp .net 多文件上传(二)第4张
192asp .net 多文件上传(二)第4张try{
193asp .net 多文件上传(二)第4张elSel.add(elOptNew,null);//standardscompliant;doesn'tworkinIE
194asp .net 多文件上传(二)第4张}
195asp .net 多文件上传(二)第4张catch(ex){
196asp .net 多文件上传(二)第4张elSel.add(elOptNew);//IEonly
197asp .net 多文件上传(二)第4张}
198asp .net 多文件上传(二)第4张}
199asp .net 多文件上传(二)第4张
200asp .net 多文件上传(二)第4张functionremoveOptionLast()
201asp .net 多文件上传(二)第4张{
202asp .net 多文件上传(二)第4张varelSel=document.getElementById(SelectControlID);
203asp .net 多文件上传(二)第4张if(elSel.length>0)
204asp .net 多文件上传(二)第4张{
205asp .net 多文件上传(二)第4张elSel.remove(elSel.length-1);
206asp .net 多文件上传(二)第4张}
207asp .net 多文件上传(二)第4张}
208asp .net 多文件上传(二)第4张functiongetOption(split)
209asp .net 多文件上传(二)第4张{
210asp .net 多文件上传(二)第4张if(!split)
211asp .net 多文件上传(二)第4张split=',';
212asp .net 多文件上传(二)第4张varelSel=document.getElementById(SelectControlID);
213asp .net 多文件上传(二)第4张vari;
214asp .net 多文件上传(二)第4张varstr='';
215asp .net 多文件上传(二)第4张for(i=elSel.length-1;i>=0;i--){
216asp .net 多文件上传(二)第4张str+=elSel.options[i].value+split;
217asp .net 多文件上传(二)第4张}
218asp .net 多文件上传(二)第4张returnstr;
219asp .net 多文件上传(二)第4张}
220asp .net 多文件上传(二)第4张functionCheckOption(value)
221asp .net 多文件上传(二)第4张{
222asp .net 多文件上传(二)第4张varelSel=document.getElementById(SelectControlID);
223asp .net 多文件上传(二)第4张vari;
224asp .net 多文件上传(二)第4张for(i=elSel.length-1;i>=0;i--){
225asp .net 多文件上传(二)第4张if(elSel.options[i].value==value)
226asp .net 多文件上传(二)第4张returntrue;
227asp .net 多文件上传(二)第4张}
228asp .net 多文件上传(二)第4张returnfalse;
229asp .net 多文件上传(二)第4张}
230asp .net 多文件上传(二)第4张//-->
231asp .net 多文件上传(二)第4张</script>";
232asp .net 多文件上传(二)第21张#endregion
233asp .net 多文件上传(二)第21张}
234asp .net 多文件上传(二)第250张}
235asp .net 多文件上传(二)第251张
使用方法如下:
在页面中加入上面的控件,ID为:FileUpLoadEx1
asp .net 多文件上传(二)第252张{
10asp .net 多文件上传(二)第253张try11asp .net 多文件上传(二)第254张asp .net 多文件上传(二)第255张asp .net 多文件上传(二)第252张{
12asp .net 多文件上传(二)第253张uploadfile(files[i],folder);
13asp .net 多文件上传(二)第254张asp .net 多文件上传(二)第255张InfoTips=string.Format("文件\"asp .net 多文件上传(二)第252张{0}\"上载成功!",files[i].FileName);
14asp .net 多文件上传(二)第261张}
15asp .net 多文件上传(二)第253张catch(Exceptionee)
16asp .net 多文件上传(二)第254张asp .net 多文件上传(二)第255张asp .net 多文件上传(二)第252张{
17asp .net 多文件上传(二)第253张IsError=true;
18asp .net 多文件上传(二)第254张asp .net 多文件上传(二)第255张InfoTipsLog.Exception(string.Format("文件\"asp .net 多文件上传(二)第252张{0}\"上载出错!错误:{1}",files[i].FileName,ee.Message));
19asp .net 多文件上传(二)第253张logInfo.Exception(ee);
20asp .net 多文件上传(二)第261张}
21asp .net 多文件上传(二)第272张}
22asp .net 多文件上传(二)第273张if(!IsError)
23asp .net 多文件上传(二)第273张Return("上载成功.");

免责声明:文章转载自《asp .net 多文件上传(二)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇SciPy模块应用GNUPLOT画图工具下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

JAVA 实现CLOB转String

CLOB定义了用于在数据库中保存文件的类型。SQLCLOB是一种内置类型,它将一个大型字符对象作为列值存储在数据库表的一行中。默认情况下,驱动程序使用SQLlocator实现Clob对象,这意味着Clob对象包含指向SQLCLOB数据的逻辑指针,而不是数据本身。Clob对象在其创建的事务期间有效。在一些数据库系统中,文本也用作CLOB的别名。例如,SQL S...

Jdk升级到11引起的问题:程序包javax.xml.bind.annotation不存在

您可以看到ELDict类中有一个引用:importjavax。xml。绑定注释XmlAttribute;虽然未使用,但它会导致mvn编译错误。在在线绑定中搜索“包javax.xml.bind.nannotation不存在”。结果是:包javax。xml。bind Annotation不存在-CSDN论坛2009年12月2日·无法编译使用jaxb的类,因为软件...

Python-正则

,三:量词*重复0次或多次{0,}+重复一次或多次{1,}?重复0或1次{1,0}{n}重复n次{n}{n,}重复n次,或更多次{n,m}将n次重复到m次Escape:如果字符串中有特殊字符要匹配,请在常规字符和字符串前面添加r。如果特殊字符在字符组中,则它们是匹配的特殊字符,但为了记忆,匹配时会转义所有特殊字符。...

[转]从minio中读取文件流进行下载文件

本文转自:https://blog.csdn.net/ZHANGLIZENG/article/details/82892678一、获取Minio连接publicstaticStringminioUrl;publicstaticStringminioUsername;publicstaticStringminioPassword;@Value("${syste...

戴尔服务器R740-iDRAC管理卡远程安装系统

Dell服务器R740 iDRAC管理卡安装系统1.方案部署:1.服务器配置名称配置备注CPU 2核心内存128GSwap=128G硬盘2T*8RAID5=12T II。设置iDRAC管理卡地址和连接:iDRAC功能默认关闭,需要在BIOS中启用。由于这是一项测试,默认情况下使用浏览器(Google浏览器)访问iDRAC管理地址,Calvin可以在此处设置新...

如何修改cmd控制台默认编码为utf-8

如何修改cmd控制台默认编码为utf-81.打开cmd窗口后,在窗口顶部右击选择属性,选中选项后会看到默认编码为gbk2.然后我们在默认窗口路径内,输入chcp命令后回车936就表示gbk编码3.然后在窗口中输入chcp65001,然后回车,即可看到窗口默认编码为utf-8编码了(65001代表utf-8编码)4.上面的方法每次都要重新设置,接下来的方法是永...