Wednesday, February 18, 2015

Upload multiple files with ASP.Net new feature in VS 2012

Create a folder with Name Files in the Application.




Design the form as follows:


 <div>

        <asp:FileUpload ID="flupload" runat="server"  AllowMultiple="true"/>
        <asp:Button ID="btnUpload" Text="Upload" runat="server"  OnClick="btnUpload_Click"/>
        <asp:Label ID="lblMessage" runat="server"  />
    </div>



.cs Page





.cs Page.

protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnUpload_Click(object sender, EventArgs e)
    {
        foreach (HttpPostedFile postedFile in flupload.PostedFiles)
        {
            string fileName = Path.GetFileName(postedFile.FileName);
            postedFile.SaveAs(Server.MapPath("~/Files/") + fileName);
        }
        lblMessage.Text = string.Format("{0} files have been uploaded successfully.", flupload.PostedFiles.Count);
    }
Output:



Click on Browse Button.



Select the Files and Click on Upload.


Click on Upload


After uploading you can see the files in your folder which you have created (Files). Just Refresh the Folder.

No comments:

Post a Comment

Thank you for visiting my blog

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...