This is a migrated thread and some comments may be shown as answers.

[Solved] Multiple uploader on single page

2 Answers 111 Views
Upload
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Taran
Top achievements
Rank 1
Taran asked on 07 Nov 2011, 02:39 PM
I am using ASP.NET MVC package that you provide free. Now i want to you uploader on my MVC application. Actually issue is that i am showing 15 records on single page and i want to upload functionality on each record. But i failed to do this with single method. Let me explain in code also:

VIEW:
----------------------------------------------------------------------------------------------------------------------------------------------
Say these are my uploder controls on single page
----------------------------------------------------------------------------------------------------------------------------------------------
1. @Html.Telerik().Upload().Name("myUpload").Multiple(false).Async(async => async.Save("SaveUpload", "MyControllerReports").AutoUpload(true))
2. @Html.Telerik().Upload().Name("myUpload").Multiple(false).Async(async => async.Save("SaveUpload", "MyControllerReports").AutoUpload(true))
3. @Html.Telerik().Upload().Name("myUpload").Multiple(false).Async(async => async.Save("SaveUpload", "MyControllerReports").AutoUpload(true))
4. @Html.Telerik().Upload().Name("myUpload").Multiple(false).Async(async => async.Save("SaveUpload", "MyControllerReports").AutoUpload(true))
5. @Html.Telerik().Upload().Name("myUpload").Multiple(false).Async(async => async.Save("SaveUpload", "MyControllerReports").AutoUpload(true))
----------------------------------------------------------------------------------------------------------------------------------------------
CONTROLLER (METHOD):
----------------------------------------------------------------------------------------------------------------------------------------------
public ActionResult SaveUpload(IEnumerable<HttpPostedFileBase> myUpload)
        {
            try
            {
                string URLPath = "~/Upload";
                bool IsExist = System.IO.Directory.Exists(Server.MapPath(URLPath));
                if (IsExist)
                { }
                else
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath(URLPath));
                }

                foreach (var item in myUploadTra)
                {
                    var FileName = Path.GetFileName(item.FileName);
                    var destinationpath = Path.Combine(Server.MapPath(URLPath), FileName);
                    item.SaveAs(destinationpath);
                }
                return Content("");
            }
            catch (Exception)
            {
                throw;
            }
}
----------------------------------------------------------------------------------------------------------------------------------------------
But i failed to do this, only 1 upload is working first one only. Is there any error in My code ???
Do  i have to create as much method as much uploads i want on page ???

Please reply soon,

Thanks

2 Answers, 1 is accepted

Sort by
0
Gordon
Top achievements
Rank 1
answered on 25 Jan 2012, 12:34 AM
I'm having a similar issue. I have four upload controls on the same page, but only the first one actually works. All of them open the choose file dialog when clicked, but only the first actually does any uploading.
0
Gordon
Top achievements
Rank 1
answered on 25 Jan 2012, 07:35 AM
I solved my issue, and Taran I see you have exactly the same issue.
Our problem is that we gave all the upload controls the same name. They must all have different names. Doing this then creates the further issue of if the multiple upload controls all use the same function for their uploading, having different names results in the parameter to the upload function being null because the name no longer matches.
To get around this, you can pass an extra parameter to the .Save() section in order to tell it what the attribute should be.
For example, to fix Taran's code above, use the following code:

VIEW:
1 @Html.Telerik().Upload().Name("myUpload1").Multiple(false).Async(async => async.Save("SaveUpload", "MyControllerReports", "myUpload").AutoUpload(true))
2 @Html.Telerik().Upload().Name("myUpload2").Multiple(false).Async(async => async.Save("SaveUpload", "MyControllerReports", "myUpload").AutoUpload(true))
3 @Html.Telerik().Upload().Name("myUpload3").Multiple(false).Async(async => async.Save("SaveUpload", "MyControllerReports", "myUpload").AutoUpload(true))
4 @Html.Telerik().Upload().Name("myUpload4").Multiple(false).Async(async => async.Save("SaveUpload", "MyControllerReports", "myUpload").AutoUpload(true))
5 @Html.Telerik().Upload().Name("myUpload5").Multiple(false).Async(async => async.Save("SaveUpload", "MyControllerReports", "myUpload").AutoUpload(true))

The Controller code remains exactly the same. No changes required.
Hopefully this fixes your issue, Taran,
Tags
Upload
Asked by
Taran
Top achievements
Rank 1
Answers by
Gordon
Top achievements
Rank 1
Share this question
or