Click here to Skip to main content
14,771,786 members
Articles » Web Development » Client side scripting » General
Tip/Trick
Posted 21 Jan 2013

Tagged as

Stats

57.3K views
17 bookmarked

Multiple File Upload Using jQuery

Rate me:
Please Sign up or sign in to vote.
4.50/5 (4 votes)
23 Jan 2013CPOL
How to select more than one file at a time

Introduction

The code shown in this tip helps to select more than one file at a time. Also, we can remove selected file, can restrict file type, etc. It's easy on user friendly one.

Background

You can refer to this link.

Using the Code

Refer to the code below:

<html >
<head runat="server">
    <title>Multiple file Upload</title>
    <script src="http://jquery-multifile-plugin.googlecode.com/svn/trunk/jquery.js" 
    type="text/javascript"></script>
    <script src="http://jquery-multifile-plugin.googlecode.com/svn/trunk/jquery.MultiFile.js" 
    type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:FileUpload ID="FileUploadJquery" runat="server" 
        class="multi" accept="jpg|png" />
    
    </div>
    </form>
</body>
</html>

C# code to handle fileupload control:

string fileName1 = "";
string FullName1 = "";
HttpFileCollection uploads = Request.Files;
//for (int fileCount = 0; fileCount < uploads.Count; fileCount++)
for (int fileCount = 1; fileCount < 6; fileCount++)
{
    if (fileCount < uploads.Count)
    {
        HttpPostedFile uploadedFile = uploads[fileCount];
        fileName1 = Path.GetFileName(uploadedFile.FileName);
        if (uploadedFile.ContentLength > 0)
        {
            string[] a = new string[1];
            a = uploadedFile.FileName.Split('.');
            fileName1 = a.GetValue(0).ToString() + 
            "." + a.GetValue(1).ToString();
            uploadedFile.SaveAs(Server.MapPath
            ("mobile_image/mob_img/" + fileName1));
        }
} 

The above code:

  1. Restricts the same files
  2. Restricts the number of files to be uploaded
  3. Type of files to be uploaded

etc.

Thank you.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

vinodkumarnie
Software Developer Sonata Software Pvt Ltd
India India
Hi.. I am Vinod Kumar B C from Mysore, Karnataka. I have done MCA and currently working as a Software Engineer having 3 Years of Experience in web development. I know Asp.net, C#, MVC, Sql Server, CSS, JQuery, C, C++, HTML, DB2, DataStructures.

Comments and Discussions

 
GeneralSolo faltaria un previo de las imagenes Pin
Chimeco5-Jun-13 14:15
MemberChimeco5-Jun-13 14:15 
GeneralRe: Solo faltaria un previo de las imagenes Pin
vinodkumarnie5-Jun-13 17:29
Membervinodkumarnie5-Jun-13 17:29 
GeneralMy vote of 3 Pin
whitesoul0130-Jan-13 12:52
Memberwhitesoul0130-Jan-13 12:52 
QuestionOther field data Pin
Spiff Dog21-Jan-13 8:18
MemberSpiff Dog21-Jan-13 8:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.