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 > :: </ STRONG >
< asp:LinkButton id ="LinkButton1" runat ="server" Font-Names ="Verdana" Font-Bold ="True" Font-Size ="XX-Small" > Upload Images </ asp:LinkButton > < STRONG > ::
</ STRONG > < A href ="JavaScript:document.forms[0].reset()" id ="LinkButton2" style ="FONT-WEIGHT:bold;FONT-SIZE:xx-small;FONT-FAMILY:verdana" >
Reset Form </ A > < 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 >
< 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 > :: </ STRONG >
< asp:LinkButton id ="LinkButton1" runat ="server" Font-Names ="Verdana" Font-Bold ="True" Font-Size ="XX-Small" > Upload Images </ asp:LinkButton > < STRONG > ::
</ STRONG > < A href ="JavaScript:document.forms[0].reset()" id ="LinkButton2" style ="FONT-WEIGHT:bold;FONT-SIZE:xx-small;FONT-FAMILY:verdana" >
Reset Form </ A > < 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
... {
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