ASP.NET(C#)同时上传多个文件

aspx页面:

< P >
                    
< INPUT  type ="file"  runat ="server"  size ="50" ></ P >
                
< P >
                    
< INPUT  type ="file"  runat ="server"  size ="50" ></ P >
                
< P >
                    
< INPUT  type ="file"  runat ="server"  size ="50" ></ P >
                
< P >
                    
< INPUT  type ="file"  runat ="server"  size ="50" ></ P >
                
< P >
                    
< INPUT  type ="file"  runat ="server"  size ="50" ></ P >
                
< P >< STRONG > :: &nbsp;   </ STRONG >
                    
< asp:LinkButton  id ="LinkButton1"  runat ="server"  Font-Names ="Verdana"  Font-Bold ="True"  Font-Size ="XX-Small" > Upload Images </ asp:LinkButton > &nbsp;&nbsp; < STRONG > ::
                    
</ STRONG > &nbsp;   < href ="JavaScript:document.forms[0].reset()"  id ="LinkButton2"  style ="FONT-WEIGHT:bold;FONT-SIZE:xx-small;FONT-FAMILY:verdana" >
                        Reset Form
</ A > &nbsp; < STRONG > :: </ STRONG ></ P >
                
< P >
                    
< asp:Label  id ="Label1"  runat ="server"  Font-Names ="verdana"  Font-Bold ="True"  Font-Size ="XX-Small"  Width ="400px"  BorderStyle ="None"  BorderColor ="White" ></ asp:Label ></ P >

 aspx.cs页面: 

private   void  Page_Load(System.Object sender, System.EventArgs e)
        
{
            
if ( this.IsPostBack ) 
                
this.SaveImages();
        }


        
private  System.Boolean SaveImages()  {
            
            System.Web.HttpFileCollection _files 
= System.Web.HttpContext.Current.Request.Files;
            
            System.Text.StringBuilder _message 
= new System.Text.StringBuilder("Files Uploaded:<br>");
                
            
try 
            
{
                
for ( System.Int32 _iFile = 0; _iFile < _files.Count; _iFile ++ ) 
                
{
            
                                    
                    System.Web.HttpPostedFile _postedFile 
= _files[_iFile]; 
                    System.String _fileName, _fileExtension;    

                    _fileName 
= System.IO.Path.GetFileName(
                    _postedFile.FileName);
                    
                    _fileExtension 
= System.IO.Path.GetExtension(
                        _fileName);

                    
if ( _fileExtension == ".gif" ) 
                    
{
                    
    
                        _postedFile.SaveAs( 
                            System.Web.HttpContext.Current.Request.MapPath(
                            
"gifs/"+ _fileName);
                        _message.Append(_fileName 
+ "<BR>");
                    
                    }

                    
else if ( _fileExtension == ".jpg" ) 
                    
{

                    
                        _postedFile.SaveAs( 
                            System.Web.HttpContext.Current.Request.MapPath(
                            
"jpgs/"+ _fileName);
                        _message.Append(_fileName 
+ "<BR>");
                
                    }
 
                    
else {
                    
                    _message.Append(_fileName 
+ " <font color="red">failed!! Only .gif and .jpg images allowed!</font> <BR>");
                    
                    }


                }

                
                Label1.Text 
= _message.ToString();
                
return true;
            }

            
catch ( System.Exception Ex ) 
            

            
                Label1.Text 
= Ex.Message ;
                
return false;          
            
            }


        }

        
#endregion
本人没有上传过大文件,有用过的回来说一下,本人表示感谢!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值