Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Multiple File Upload
WhatsApp
Hemlata Kushwaha
Aug 11
2015
1.1
k
0
0
<%@ 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 Upload
Multiple File Selection.
Up Next
Multiple File Upload