TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Multiple File Upload
Hemlata Kushwaha
Aug 11
2015
Code
1.1
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
<%@ Page Language=
"C#"
AutoEventWireup=
"true"
CodeFile=
"CS.aspx.cs"
Inherits=
"CS"
%>
<!DOCTYPE html>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head runat=
"server"
>
<title></title>
<style type=
"text/css"
>
body { font-family: Arial; font-size: 10pt; }
</style>
</head>
<body>
<form id=
"form1"
runat=
"server"
>
<div>
<input type=
"file"
id=
"myfile"
multiple=
"multiple"
name=
"myfile"
runat=
"server"
size=
"100"
/>
<br />
<asp:Button ID=
"Button1"
runat=
"server"
Text=
"Button"
OnClick=
"Button1_Click"
/>
<br />
<asp:Label ID=
"Span1"
runat=
"server"
></asp:Label>
</div>
</form>
</body>
</html>
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.IO;
public
partial
class
CS : System.Web.UI.Page
{
protected
void
UploadMultipleFiles(
object
sender, EventArgs e)
{
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
HttpFileCollection uploadedFiles = Request.Files;
string
filepath = Server.MapPath(
"~/Uploads/"
);
Span1.Text =
string
.Empty;
for
(
int
i = 0; i < uploadedFiles.Count; i++)
{
HttpPostedFile userPostedFile = uploadedFiles[i];
try
{
if
(userPostedFile.ContentLength > 0)
{
Span1.Text +=
"<u>File #"
+ (i + 1) +
"</u><br>"
;
Span1.Text +=
"File Content Type: "
+ userPostedFile.ContentType +
"<br>"
;
Span1.Text +=
"File Size: "
+ userPostedFile.ContentLength +
"kb<br>"
;
Span1.Text +=
"File Name: "
+ userPostedFile.FileName +
"<br>"
;
userPostedFile.SaveAs(System.IO.Path.Combine(Server.MapPath(
"~/Uploads/"
), userPostedFile.FileName));
Span1.Text +=
"Location where saved: "
+ filepath +
"\\" + Path.GetFileName(userPostedFile.FileName) + "
<p>";
}
}
catch
(Exception Ex)
{
Span1.Text +=
"Error: <br>"
+ Ex.Message;
}
}
}
}
Multiple File Selection.
Multiple File Upload