Uploadng Multiple FIles

Sandhyab
Posted by Sandhyab under ASP.NET category on | Points: 40 | Views : 1368
aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="uploadmultiplefiles.aspx.cs" Inherits="uploadmultiplefiles" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<asp:FileUpload ID="FileUpload2" runat="server" /><br />
<asp:FileUpload ID="FileUpload3" runat="server" /><br />
<asp:FileUpload ID="FileUpload4" runat="server" /><br />
<br />
<asp:Button ID="btn1" runat="server" Text="Upload Files" OnClick="upload" />
</div>
</form>
</body>
</html>


Code Behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class uploadmultiplefiles : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void upload(object sender, EventArgs e)
{
HttpFileCollection files = Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
string filename = file.FileName;
string path = Server.MapPath("~/");
file.SaveAs(path + filename);
Response.Write("file " + filename + " uploaded<br/>");
}
}
}

Comments or Responses

Login to post response