兄弟~偶贴出这段多文件上传的完整代码,你参考对比一下是哪点错了,我贴的这个是200%正确的: public class UPLOAD : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton LinkButton1; #region User Defined Code

protected System.Web.UI.WebControls.Label Label1;

private void Page_Load(System.Object sender, System.EventArgs e)
{
if ( this.IsPostBack ) 
this.SaveImages();
} private System.Boolean SaveImages() {
//loop through the files uploaded System.Web.HttpFileCollection _files = System.Web.HttpContext.Current.Request.Files;

//Message to the user
System.Text.StringBuilder _message = new System.Text.StringBuilder("Files Uploaded:<br>");

try 
{
for ( System.Int32 _iFile = 0; _iFile < _files.Count; _iFile ++ ) 
{

// Check to make sure the uploaded file is a jpg or gif

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" ) 
{

//Save File to the proper directory
_postedFile.SaveAs( 
System.Web.HttpContext.Current.Request.MapPath(
"gifs/") + _fileName);
_message.Append(_fileName + "<BR>");

}
else if ( _fileExtension == ".jpg" ) 
{ //Save File to the proper directory
_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;   

} }================================================================
aspx页
<%@ Page language="c#" Codebehind="UPLOAD_CS.aspx.cs" AutoEventWireup="false" Inherits="HowTos.MultipleImageUpdate.UPLOAD" %>
<HTML>
<HEAD>
<title>::: UPLOAD SAMPLE ::: </title>
</HEAD>
<body>
<center>
<form id="UPLOAD" method="post" runat="server" enctype="multipart/form-data">
<h3>Multiple File Upload Example</h3>
<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; <A 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>
<P>&nbsp;</P>
</form>
</center>
</body>
</HTML>

解决方案 »

  1.   

    是呀,因为你是用for循环呀,程序执行了5次!当遇到空值的inputfile时,就跳到catch(Exception ee)捕获异常了呀。这是肯定的。你的意思是这样吧?
      

  2.   

    错就错在这里吧:
    HtmlInputFile hif=(HtmlInputFile)Panel1.FindControl("File"+i.ToString());
    if(hif!=null )if(hif!=null) 这句 =null就跳到异常吧~
      

  3.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=58EA3515-36F2-4FD9-AC89-EAF49F59816C
      

  4.   

    to:1122111(阿超) ,问题是当5个inputfile控件的文本框里都有上传文件名时上传会成功啊