Click here to Skip to main content
15,910,661 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
JavaScript
$(document).ready1(function () {

        // up to 3 files can be selected

        // invoke plugin
        $('#ctl00_ContentPlaceHolder1_flpProspectus').MultiFile(5);

        // if you send in a number the plugin
        // will treat it as the file limit

    });
$(document).ready2(function () {

        // up to 3 files can be selected

        // invoke plugin
        $('#ctl00_ContentPlaceHolder1_flpEnquiry').MultiFile(5);

        // if you send in a number the plugin
        // will treat it as the file limit

    });

ASP.NET
 <asp:FileUpload ID="flpProspectus" class="form-control"  runat="server"  Style="width: 50%; margin-top: -50px;float:left; margin-left:90%" />
<asp:FileUpload ID="flpEnquiry" class="form-control"  runat="server"  Style="width: 50%; margin-top: -50px;float:left; margin-left:90%" />


Cs Page code---
C#
public void FileUpload1()
    {
        if (flpOrientation.HasFile)
        {
            string fileExtension = System.IO.Path.GetExtension(flpProspectus.FileName);
            int fileSize = flpProspectus.PostedFile.ContentLength;
            HttpFileCollection hfc = Request.Files;
            string[] arr = new string[5];
            for (int i = 0; i < hfc.Count; i++)
            {
                HttpPostedFile hpf = hfc[i];
                if (hpf.ContentLength > 0)
                {
                    hpf.SaveAs(Server.MapPath("~/college/fileupload3/") + System.IO.Path.GetFileName(hpf.FileName));
                    string filepath = Server.MapPath("~/college/fileupload3/");
                    string path = "college/fileupload3/" + hpf.FileName;
                    if (i < 5)
                    {
                        arr[i] = path;
                        path1 = arr[0]; path2 = arr[1]; path3 = arr[2]; path4 = arr[3]; path5 = arr[4];

                    }

                }
            }
        }
    }


What I have tried:

Above I mention Code-
I Want to know When i Just Choose File From FileUpload Control it is working Fine
but when i Choose one File From First File Control and One Choose File From Second FileUpload Control Then Both File is Stored in Same Folder and my Loop Condition working for both control so how to solve this issue when i choose First FileUpload Control then My Loop Condition Only Work First Control So Please Help Me-

I am Using File Upload Code of This Link--

jQuery MultiFile v2.2.1[^]
Posted
Updated 25-Mar-17 7:36am
v3

1 solution

If you want to get multiple files from two different FileUpload controls and then save in two different folders on a single button click event. You can use this code its easy...
HTML
ASP.NET
<form id="form1" runat="server">
    <div class="uploadContainer">
        <asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" />
        <asp:Label ID="lblmessage1" runat="server" ForeColor="Red" />
        <br />
        <asp:FileUpload ID="FileUpload2" runat="server" AllowMultiple="true" />
        <asp:Label ID="lblmessage2" runat="server" ForeColor="Red" />
        <br />
        <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="UploadMultipleFile_Click" />
        <br />
        
    </div>
    </form>


C#
C#
 protected void UploadMultipleFile_Click(object sender, EventArgs e)
 {
 if (FileUpload1.HasFiles && FileUpload2.HasFiles)
        {
            foreach (HttpPostedFile postedFile in FileUpload1.PostedFiles)
            {
                lblmessage1.Text = string.Empty;
                string fileName = Path.GetFileName(postedFile.FileName);
                postedFile.SaveAs(Server.MapPath("~/Uploads1/") + fileName);
                lblmessage1.Text = FileUpload1.PostedFiles.Count + " files have been uploaded successfully.";
            }
          foreach (HttpPostedFile postedFile in FileUpload2.PostedFiles)
            {
                lblmessage2.Text = string.Empty;
                string fileName = Path.GetFileName(postedFile.FileName);
                postedFile.SaveAs(Server.MapPath("~/Uploads2/") + fileName);
                lblmessage2.Text = FileUpload1.PostedFiles.Count + " files have been uploaded successfully.";
            }
        }
        else
        {
            lblmessage1.Text = " ";
            lblmessage2.Text = " ";
        }
}
 
Share this answer
 
v2
Comments
Member 12183079 25-Mar-17 23:22pm    
Dear sir
when i try this code then i get error in hasfiles and PostedFiles and i want to strore path in array index because i want to pass in column where i made in table so kinley help me

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900