<%@ Page Language="C#" AutoEventWireup="true" CodeFile="pageload.aspx.cs" Inherits="pageload" %>
<!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 runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="UPLOAD" method="post" runat="server" enctype="multipart/form-data">
<h3>Multiple File Upload Example</h3>
<input id="File1" type="file" runat="server" size="50"/>
<p>
<input id="File2" type="file" runat="server" size="50"/></p>
<p>
<input id="File3" type="file" runat="server" size="50"/></p>
<p>
<input id="File4" type="file" runat="server" size="50"/></p>
<p>
<input id="File5" type="file" runat="server" size="50"/></p>
<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> 
<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> </p>
</form>
</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;
public partial class pageload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
this.SaveImages();
}
#region
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;
}
}
#endregion
#region Web Form Designer generated code
override protected void OnInit(System.EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
#endregion
#region Web Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}