my requirement is, when i click on browse buttton, i shud be able to select multiple images at a time, not clicking browse button every time for every image nd uploading all at once
then i shud be able to use upload button, i want event handler in upload button
lot of application in net are using flash buttons for uploading button, or clicking on browse button every time for selecting every image, or when we select multiple images, directly they are getting uploaded with the use of upload button...
Nice! Awesome solution! I hate when people always just simply suggest some third-party control when you really want a solution you can develop yourself. Great suggestion and I think may check this out too.
Another solution I was thinking of trying was the following:
adding a set number of fileupload controls, lets say 5 for an example.
then on click of the upload button, get the 5 controls from the control container and insert them into a List<FileUpload> and create a method that accepts this list as a parameter. In the method do a foreach loop that performs all the validation on each
control's filestream and, if valid, performs the upload. Could even get fancy if you wanted and run each upload on it's own background thread asynchronously.
I like the method you described though as it allows you to bind the gridview to the files on the pc. One question though, to allow the gridview to be bound to the filepath from the client machine, does it require any permissions? I mean will it ask the user
to allow the page to access local files or will it just do it automatically? I never really tried it before
When the going get's tough, the tough outsource and take a vacation... lol I wish :(
When I try your solution in IE9, on either single or multiple file, IE9 just replaces the contents with the first file being dropped, and all else vanishes. I must be doing some minor error. Besides, your code does not work straight off the box. I had to
resort to some modifications, but I do not think they are to blame, since they come
after the files have been dropped.
There must be something trivial I am doing wrong. I even tried it in Firefox, with the same result, i.e. the first file dropped fills the browser screen. What are the others doing that I am not?
I can post my code, but await the 2 second answer first :-)
alwaysonline
Member
174 Points
220 Posts
how to upload multiple files at a time?
Sep 21, 2011 04:42 AM|LINK
how can we upload multiple files at a time...
my requirement is, when i click on browse buttton, i shud be able to select multiple images at a time, not clicking browse button every time for every image nd uploading all at once
then i shud be able to use upload button, i want event handler in upload button
lot of application in net are using flash buttons for uploading button, or clicking on browse button every time for selecting every image, or when we select multiple images, directly they are getting uploaded with the use of upload button...
thanks in advance
mayank arora
Member
238 Points
51 Posts
Re: how to upload multiple files at a time?
Sep 21, 2011 04:57 AM|LINK
Hi ,
USE Yahoo Yui Toolkit (multiple file uploader)
http://developer.yahoo.com/yui/examples/uploader/uploader-advanced-queue.html
or use Silverlight multiple file uploader.
Mayank Arora
Don't forget to click “Mark as Answer” on the post that helped you.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: how to upload multiple files at a time?
Sep 23, 2011 01:31 AM|LINK
Hello alwaysoline,
protected void btnUpload_Click(object sender, EventArgse)
<div style="margin: 0in 0in 0pt; line-height: normal;"> {</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> try</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> {</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> // Get the HttpFileCollection</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> HttpFileCollection hfc = Request.Files;</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> for (int i = 0; i < hfc.Count; i++)</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> {</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> HttpPostedFile hpf = hfc[i];</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> if (hpf.ContentLength > 0)</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> {</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> hpf.SaveAs(Server.MapPath("MyFiles") + "\\" +</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> System.IO.Path.GetFileName(hpf.FileName));</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> Response.Write("<b>File: </b>" + hpf.FileName + " <b>Size:</b> " +</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> hpf.ContentLength + " <b>Type:</b> " + hpf.ContentType + " Uploaded Successfully <br/>");</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> }</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> }</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> }</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> catch (Exception ex)</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> {</div> <div style="margin: 0in 0in 0pt; line-height: normal;"> </div> <div style="margin: 0in 0in 0pt; line-height: normal;"> }</div> <div style="margin: 0in 0in 10pt;"> }</div> <div style="margin: 0in 0in 10pt;"> <div style="margin: 0in 0in 10pt;">alwaysonline
Member
174 Points
220 Posts
Re: how to upload multiple files at a time?
Sep 23, 2011 06:25 AM|LINK
not the above one, we shud be able to select multiple images in a single browse click nd then upload
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: how to upload multiple files at a time?
Sep 23, 2011 06:51 AM|LINK
Hello alwaysonline:)
In fact I think you can try this:
1) Drag and drop a GridView and set two fields: One is checkboxfield, while the other is a common BoundField.
<asp:GridView ……>
<Columns>
<asp:Template HeaderText="Choose Files">
<ItemTemplate>
<asp:CheckBox Id="chkBox" runat="server"/>
</ItemTemplate>
</asp:Template>
<asp:Template HeaderText="File Path">
<ItemTemplate>
<asp:Label Id="lbFilePath" runat="server" Text='<%#Eval("FilePath")%>'/>
</ItemTemplate>
</asp:Template>
</Columns>
</asp:GridView>
<asp:Button Id="btnSubmit" runat="server" Text="Upload All" />
Your codes behind:
var result = from path in Directory.GetFiles("Your File Path From your PC","*.*",SearchOption.AllDirectories);
select new
{
FilePath = path
};
GridView.DataSource = result;
GridView.DataBind();
And in the end, double click the button and say——
FileUpLoad fp = new FileUpLoad();
foreach(GridViewRow row in GridView.Rows)
{
CheckBox chkbox = (CheckBox)row.FindControl("chkBox");
if(chkbox.Checked)
{
Label lb = (Label)row.FindControl("lbFilePath");
fp.SaveAs(Server.MapPath("~/Files/")+new FileInfo(lb.Text).FileName;
}
}
magicmike201...
Contributor
2021 Points
481 Posts
Re: how to upload multiple files at a time?
Nov 11, 2011 03:09 AM|LINK
Nice! Awesome solution! I hate when people always just simply suggest some third-party control when you really want a solution you can develop yourself. Great suggestion and I think may check this out too.
Another solution I was thinking of trying was the following:
adding a set number of fileupload controls, lets say 5 for an example.
then on click of the upload button, get the 5 controls from the control container and insert them into a List<FileUpload> and create a method that accepts this list as a parameter. In the method do a foreach loop that performs all the validation on each control's filestream and, if valid, performs the upload. Could even get fancy if you wanted and run each upload on it's own background thread asynchronously.
I like the method you described though as it allows you to bind the gridview to the files on the pc. One question though, to allow the gridview to be bound to the filepath from the client machine, does it require any permissions? I mean will it ask the user to allow the page to access local files or will it just do it automatically? I never really tried it before
drDubbelklic...
Member
2 Points
1 Post
Re: how to upload multiple files at a time?
Apr 13, 2013 06:51 AM|LINK
Hello,
When I try your solution in IE9, on either single or multiple file, IE9 just replaces the contents with the first file being dropped, and all else vanishes. I must be doing some minor error. Besides, your code does not work straight off the box. I had to resort to some modifications, but I do not think they are to blame, since they come after the files have been dropped.
There must be something trivial I am doing wrong. I even tried it in Firefox, with the same result, i.e. the first file dropped fills the browser screen. What are the others doing that I am not?
I can post my code, but await the 2 second answer first :-)