Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to upload multiple files to a grid before I save the file information into database . Is this possible....?

Thanks.
Posted
Comments
Gitanjali Singh 12-Aug-13 3:22am    
yes it is possible.This can be done using fileupload control or custom multiple file upload control.Which control do you need?
Member 9861478 12-Aug-13 3:23am    
Could you please guide through best as you might know better.. really appreciated for quick response.
Thanks,

1 solution

Using both ways you can achieve this.Fileupload control is built in control in ASP.net.

Here is the HTML Code.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="jquery.js" type="text/javascript"></script>
    <script src="jquery.MultiFile.js" type="text/javascript"></script>
   
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:fileupload id="FileUpload1" runat="server" xmlns:asp="#unknown" />
<br />
<asp:fileupload id="FileUpload2" runat="server" xmlns:asp="#unknown" />
<br />
<asp:fileupload id="FileUpload3" runat="server" xmlns:asp="#unknown" />
<br />
<asp:fileupload id="FileUpload4" runat="server" xmlns:asp="#unknown" />
</div>         
  
<asp:button id="btnUpload" runat="server" xmlns:asp="#unknown">
            onclick="btnUpload_Click" 
            Text="Upload Files"/><br /><br />
</form>
</body>
</html>
</asp:button>

Code to save the files on Button click.
C#
protected void btnUpload_Click(object sender, EventArgs e)
   {
       HttpFileCollection uploads = Request.Files;
       for (int fileCount = 0; fileCount < uploads.Count; fileCount++)
       {
           HttpPostedFile uploadedFile = uploads[fileCount];
           string fileName = Path.GetFileName(uploadedFile.FileName);
           if (uploadedFile.ContentLength > 0 )
           {
               uploadedFile.SaveAs(Server.MapPath("~/Files/") + fileName);
               lblMessage.Text += fileName + "Uploaded <br />";
           }
       }
   }

Here the uploaded files are get saved into server,in yours case you can extract the details of file and save it to database.

Hope this one help.

Thanks.


[Edit member="Tadit"]
Formatted Text.
[/Edit]
 
Share this answer
 
v2

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