What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 15192 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > ASP.NET > Uploading Multiple file in asp.net (c#) ...
Bageshkumarbagi

Uploading Multiple file in asp.net (c#)

 Code Snippet posted by: Bageshkumarbagi | Posted on: 10/5/2012 | Category: ASP.NET Codes | Views: 2271 | Status: [Member] | Points: 40 | Alert Moderator   


HTML CODE
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>

<!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>To Upload Multiple File in ASP.NET </title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Upload Multiple Files in Asp.net Using C# code</h1>
<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" /> </div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Upload Files" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>

===========C# code===========
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;

namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
HttpFileCollection multipleFiles = Request.Files;
for (int fileCount = 0; fileCount < multipleFiles.Count; fileCount++)
{
HttpPostedFile uploadedFile = multipleFiles[fileCount];
string fileName = Path.GetFileName(uploadedFile.FileName);
if (uploadedFile.ContentLength > 0 )
{
uploadedFile.SaveAs(Server.MapPath("~/Files/") + fileName);
Label1.Text += fileName + "Saved <BR>";
}
}

}
}
}

=====================
You need to create a Folder in Solutation Explorer which name is " Files "
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/24/2013 4:32:43 PM