Upload Multiple Files In ASP.NET With Example
code , code for Multiple File , Example of Multiple File , ASP.NET in Multiple File.
UploadMultipleFilesExample.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="UploadMultipleFilesExample.aspx.cs" Inherits="UploadMultipleExample.UploadMultipleFilesExample" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Upload Multiple Files</h3>
<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" />
</div>
<p>
<asp:Button ID="Button1" runat="server" Text="Upload File" OnClick="Button1_Click" />
</p>
</form>
<p>
<asp:Label runat="server" ID="FileUploadStatus"></asp:Label>
</p>
</body>
</html>
UploadMultipleFilesExample.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace UploadMultipleExample
{
public partial class UploadMultipleFilesExample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if ((FileUpload1.PostedFile != null) && (FileUpload1.PostedFile.ContentLength > 0))
{
var count = 0;
foreach (HttpPostedFile uploadedFile in FileUpload1.PostedFiles)
{
string fn = System.IO.Path.GetFileName(uploadedFile.FileName);
string SaveLocation = Server.MapPath("upload") + "\\" + fn;
try
{
uploadedFile.SaveAs(SaveLocation);
count++;
}
catch (Exception ex)
{
FileUploadStatus.Text = "Error: " + ex.Message;
}
}
if (count > 0)
{
FileUploadStatus.Text = count + " files has been uploaded.";
}
}
else
{
FileUploadStatus.Text = "Please select a file to upload.";
}
}
}
}
code , code for Multiple File , Example of Multiple File , ASP.NET in Multiple File.
UploadMultipleFilesExample.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="UploadMultipleFilesExample.aspx.cs" Inherits="UploadMultipleExample.UploadMultipleFilesExample" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Upload Multiple Files</h3>
<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" />
</div>
<p>
<asp:Button ID="Button1" runat="server" Text="Upload File" OnClick="Button1_Click" />
</p>
</form>
<p>
<asp:Label runat="server" ID="FileUploadStatus"></asp:Label>
</p>
</body>
</html>
UploadMultipleFilesExample.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace UploadMultipleExample
{
public partial class UploadMultipleFilesExample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if ((FileUpload1.PostedFile != null) && (FileUpload1.PostedFile.ContentLength > 0))
{
var count = 0;
foreach (HttpPostedFile uploadedFile in FileUpload1.PostedFiles)
{
string fn = System.IO.Path.GetFileName(uploadedFile.FileName);
string SaveLocation = Server.MapPath("upload") + "\\" + fn;
try
{
uploadedFile.SaveAs(SaveLocation);
count++;
}
catch (Exception ex)
{
FileUploadStatus.Text = "Error: " + ex.Message;
}
}
if (count > 0)
{
FileUploadStatus.Text = count + " files has been uploaded.";
}
}
else
{
FileUploadStatus.Text = "Please select a file to upload.";
}
}
}
}
Post a Comment