-
How do I implement multiple upload using Javascript?
Hi,
I have used asp.net file upload control but it can only upload one file at a time and it blocks the UI during upload(synchronous). I however need to upload many files at once. I have not tried the one that comes with Ajax Control toolkit but I got another one. It works fine as in I can browse and choose more than one file at a time. The problem is I can't get access to the files that i choose on the client because the control is an input html control and I can't access it on the server side (C# code behind).
What am I leaving out? Please someone help...
The details are below:
Code:
var x = this.Page.FindControl("FileUpload1");
lbuploadmessage.Text = x.GetType().ToString();
HttpFileCollection hfc = Request.Files;
List<L2SQLData.PatientFile> list = new List<L2SQLData.PatientFile>();
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0 && hpf.ContentLength < 1024000)
{
string filename = Path.GetFileName(hpf.FileName);
string ext = Path.GetExtension(hpf.FileName);
var guidname = Guid.NewGuid().ToString();
//FileUpload1.SaveAs(Server.MapPath("~/Uploads/DocClerkings/") + guidname + ext);
hpf.SaveAs(Server.MapPath("~/Uploads/DocClerkings/") + guidname + ext );
lbuploadmessage.Text = "Upload status:" + hpf.FileName + " successfully uploaded!";
As you can see I named the control-"FileUpload1" but at runtime (Debug) the object x is null and Request.Files collection that's supposed to contain the browsed files is empty too. The multi - upload control looks like this:
<input id = "FileUpload1" type="file" class="multi"/>
with two scripts i added as follows:
<script src="jquery-latest.js" type="text/javascript" language="javascript"></script>
<script src="jquery.MultiFile.js" type="text/javascript" language="javascript"></script>
So what did I leave out?
Cheers
Mobile: +234 706 042 6036
Email: charles@hedonmark.com
Website: www.hedonmark.com
“To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment.”
—Ralph Waldo Emerson
-
Hi guys,
I got the javascript mark-up from this site-http://www.fyneworks.com/jquery/multiple-file-upload/#tab-Uploading. I hope someone can make sense out of this.
The author said:
Make sure your form has method=POST and enctype=multipart/form-data
I am using asp.net forms. How can I ensure this directive he gave is followed or implemented?Thanks
Mobile: +234 706 042 6036
Email: charles@hedonmark.com
Website: www.hedonmark.com
“To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment.”
—Ralph Waldo Emerson
-
I finally found the missing link at http://docs.jquery.com/Tutorials:Mul...e_Upload_Magic
Code:
var fileMax = 3;
$("input[@type=file]").change(function(){
doIt(this, fileMax);
});
These lines are all in the designer mark up.On the server side (C# code behind) in the upload button place this:
Code:
HttpFileCollection hfc = Request.Files;
List<L2SQLData.PatientFile> list = new List<L2SQLData.PatientFile>();
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0 && hpf.ContentLength < 1024000)
{
string filename = Path.GetFileName(hpf.FileName);
string ext = Path.GetExtension(hpf.FileName);
var guidname = Guid.NewGuid().ToString();
hpf.SaveAs(Server.MapPath("~/Uploads/DocClerkings/") + guidname + ext );
lbuploadmessage.Text = "Upload status:" + hpf.FileName + " successfully uploaded!";
Thanks for the assistance.
Mobile: +234 706 042 6036
Email: charles@hedonmark.com
Website: www.hedonmark.com
“To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment.”
—Ralph Waldo Emerson
-
How do I implement multiple upload using Javascript
What do you recommend that we do if we can modify our JavaScript to make our application more testable?
Similar Threads
-
By barkster in forum Java
Replies: 7
Last Post: 03-17-2008, 10:18 AM
-
By sandeshas in forum Java
Replies: 3
Last Post: 09-20-2007, 07:34 PM
-
By amyzhao in forum ASP.NET
Replies: 2
Last Post: 07-19-2007, 02:40 PM
-
By felix in forum ASP.NET
Replies: 1
Last Post: 11-11-2005, 09:39 AM
-
By Murray Foxcroft in forum Web
Replies: 5
Last Post: 11-02-2000, 03:42 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|