vijay

welcome Netizen

welcome Netizen
Hi folks this site Share Basic Knowledge in .NET, DotNet, C#,DOT NET CODE, ASP.NET, VB.NET, DOT NET TRICKS,Dotnetcode,Android and Latest Technology Articles in VB,Android and ASP.NET

Sunday, March 17, 2013

Multiple file upload in asp.net



Here I would like to share a code to upload multiple files using framework 4.0.In a previous I had post article related to multiple file upload control. For your reference below I have mention the link..
In latest framework file upload control has a default properties to upload multiple, just we need to enable the properties
Steps:
Drag the file upload control and one button
Write the below code on the button event to upload multiple files on the server
<div>
           <asp:FileUpload ID="FileUpload2" runat="server"  />
        <asp:FileUpload ID="FileUpload1" runat="server"  multiple="multiple" />
        <br />
        <asp:Button ID="btnUpload" runat="server" Text="Upload All"
            onclick="btnUpload_Click" />
    </div>

Server code:
protected void btnUpload_Click(object sender, EventArgs e)
    {
        try
        {
            // Get the HttpFileCollection
            HttpFileCollection Filecll = Request.Files;
            for (int i = 0; i < Filecll.Count; i++)
            {
                HttpPostedFile hpf = Filecll[i];
                if (hpf.ContentLength > 0)
                {
                    hpf.SaveAs(Server.MapPath("Images") + "\\" + System.IO.Path.GetFileName(hpf.FileName));
                    Response.Write("<b>File: </b>" + hpf.FileName + " <b>Size:</b> " +
                        hpf.ContentLength + " <b>Type:</b> " + hpf.ContentType + " Uploaded Successfully <br/>");
                }
            }
        }
        catch (Exception ex)
        {

        }
    }

Selected file has been moved to server images folder.
Note: when doing selection you need to select multiple file or single file to upload…
Click here to Download project file
Post your comments………

0 comments:

Post a Comment