Multiple FileUpload Demo

Posted by in ASP.NET category on for Beginner level | Views : 8967 red flag

This is simple demo of fileUpload Controls

Simple copy following code and paste on webform and run.

Multiple File Upload
<%@Page Language="C#"%>
            Multiple Files Uploading Using C# - Demo
<script language="C#" runat="Server">
    //Event handler for the upload button
    void UploadFile(object Sender,EventArgs E)
        int IntLoop=0;
        //Iterating through the Request.Files collection
            if (Request.Files[IntLoop] !=null) //Checking for valid file
                // Since the FileName gives the entire path we use Substring function to rip of the filename.
                string StrFileName =Request.Files[IntLoop].FileName.Substring(Request.Files[IntLoop].FileName.LastIndexOf("\\") + 1) ;
                string StrFileType = Request.Files[IntLoop].ContentType ;
                int IntFileSize =Request.Files[IntLoop].ContentLength;
                //Checking for the file length. If length is 0 then file is not uploaded.
                if (IntFileSize <=0)
                    Response.Write(" <font color='Red' size='2'>Uploading of file " + StrFileName + " failed. </font><br>");
                    //Saving the file to the web server
                    Request.Files[IntLoop].SaveAs(Server.MapPath(".\\" + StrFileName));
                    Response.Write( "<font color='green' size='2'>Your file " + StrFileName + " of type " + StrFileType + " and size " + IntFileSize.ToString() + " was uploaded successfully.</font><br>");
        Response.Write("<br>Click <a href='MultipleFileUploadDemo.aspx'>here</a> to upload more files");

<!-- Declaration of server side form.Note the enctype attribute of the form has to be set to multipart/form-data -->
<basefont size="2">
<form id="FrmFileUploadDemo" name="FrmFileUploadDemo"  method="post" enctype="multipart/form-data" runat="server">
    <TABLE align="center"  cellspacing="5">
                <font size="2">Select a file to upload</font> <input type="file" id="File1" name="File1" runat="server">
                <font size="2">Select a file to upload</font> <input type="file" id="File2" name="File2" runat="server">
                <font size="2">Select a file to upload</font> <input type="file" id="File3" name="File3" runat="server">
            <TD align="center">
                <asp:button value="Upload" Text="Upload" runat="server" id="CmdUpload" onClick="UploadFile" />



Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: vipul vk
Member Level: Starter
Member Status: Member
Member Since: 4/15/2009 9:08:15 PM
Working as a software developer

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)