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

[Solved] Problem with MVC Upload Control -- file names are duplicated

10 Answers 293 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.
David
Top achievements
Rank 1
Iron
David asked on 25 Oct 2011, 04:33 PM
Please help.

I have attached a screenshot of the malfunction I've experienced.  I'm trying to upload 2 files, but I see 8 files (note that 4 of them are repeated).  The files are never actually uploaded.  I'm using MVC2.

View Code:
<% using(Html.BeginForm("ProcessUploadSelect", "Auction", FormMethod.Post, new {id="uploadForm", enctype="multipart/form-data"})) { %>
        <p class="note">
            ---------<br />
            VERSION 2<br />
            Select image files to upload.
  
  
            <%= Html.Telerik().Upload()
                    .Name("attachments")
                    .Async(async => async
                        .Save("Save", "Auction")
                        .Remove("Remove","Auction")
                        .AutoUpload(true)
                    )
                    .Multiple(true)
            %>
        </p>
    <%
    } %>


Controller Code:
public ActionResult Remove(string auctionId, string[] fileNames)
        {
            foreach (var fullName in fileNames)
            {
                var fileName = Path.GetFileName(fullName);
                var physicalPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);
 
                // TODO: Verify user permissions
                if (System.IO.File.Exists(physicalPath))
                {
                    System.IO.File.Delete(physicalPath);
                }
            }
 
            // Return an empty string to signify success
            return Content("");
        }
        public ActionResult Save(IEnumerable<System.Web.HttpPostedFileBase> attachments)
        {
            // The Name of the Upload component is "attachments"
            foreach (var file in attachments)
            {
                // Some browsers send file names with full path. We only care about the file name.
                var fileName = Path.GetFileName(file.FileName);
                var destinationPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);
 
                file.SaveAs(destinationPath);
            }
 
            // Return an empty string to signify success
            return Content("");
        }

10 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 26 Oct 2011, 03:09 PM
Hi David,

You are the first to report such problem and at this point we cannot tell what might be the reason for it. Do you experience the same problem in any of our online demos? If so, please let us know what is your exact browser version and provide reproduction steps.
Your code looks OK, so if you experience the problem only in project, please send us a sample one that reproduces it so we can investigate further.

Best wishes,
Georgi Tunev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
David
Top achievements
Rank 1
Iron
answered on 26 Oct 2011, 04:03 PM
Georgi,

Thanks for checking the code.  Your website samples are working perfectly.

I may not have time to create a project to reproduce the problem.  I went with your synchronous uploader and it appears to be working.

Windows Vista Home Premium SP2 32-Bit
Visual Studio 2010 Ultimate
Firefox 7.01
Chrome 14.0.835.202 m

Your asynchronous uploader is very snazzy, but I can't put any more time into it.  I was hoping you had a quick work-around, but if not, don't worry.
0
Georgi Tunev
Telerik team
answered on 27 Oct 2011, 08:19 AM
Hello again David,

I'm sorry that we were not able to help you in this case, but it is good to know, that the sync uploader fits your scenario. I'll write back in this forum thread if someone else reports such problem and we are able to reproduce it.


Regards,
Georgi Tunev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
storyr
Top achievements
Rank 1
answered on 20 Nov 2011, 10:30 PM
I'm having the same issue - when a file is selected, it shows up twice in the list - and is uploaded twice.

Observations:
  • Each time a file is selected, the "attachments" input is duplicated (see html below).
  • One note: the upload control is dynamically loaded via ajax.

sample html (after one file select operation):
<div class="t-widget t-upload" sizcache="2032" sizset="9" jquery164008893823556807334="61">
  <div class="t-button t-upload-button" sizcache="2032" sizset="9">
    <span>Select...</span>
    <input style="display: none" id="attachments" type="file" name="attachments" autocomplete="off" multiple="multiple" jquery164008893823556807334="63">
    <input id="attachments" type="file" name="attachments" autocomplete="off" multiple="multiple" jquery164008893823556807334="62"></div>
  <ul class="t-upload-files t-reset">
    <li class="t-file" jquery164008893823556807334="64"><span class="t-icon"></span><span class="t-filename">background.png</span>
      <button class="t-button t-button-icontext t-upload-action" type="button"><span class="t-icon t-delete"></span>Remove</button></li>
    <li class="t-file" jquery164008893823556807334="66"><span class="t-icon"></span><span class="t-filename">background.png</span>
      <button class="t-button t-button-icontext t-upload-action" type="button"><span class="t-icon t-delete"></span>Remove</button></li></ul>
  <button class="t-button t-upload-selected" type="button">Upload files</button></div>

sample code:
<%= Html.Telerik().Upload()
      .Name("attachments")
      .Async(async => async
          .Save("Upload", "Record")
          .Remove("RemoveUpload", "Record")
          .AutoUpload(false)
      )
      .Multiple(true)
      .ClientEvents(c => c
        .OnSelect("xManageRecord.onFileSelect")
        .OnUpload("xManageRecord.onFileUpload")
      )

0
T. Tsonev
Telerik team
answered on 21 Nov 2011, 10:30 AM
Hello Storyr,

This is a known issue with IE8 caused by a jQuery bug. Updating to jQuery 1.7 solves it, but creates problems on it's own. We're waiting for the 1.7.1 release to address them.

Please let us know if the bug occurs in other browsers as well.

Greetings,
Tsvetomir Tsonev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
SUNG
Top achievements
Rank 1
answered on 24 Nov 2011, 02:45 AM
I have same problem too. Is there any workaround?
0
T. Tsonev
Telerik team
answered on 24 Nov 2011, 10:54 AM
Hi Sung,

We will include a fix for the issue in the upcoming Service Pack release. Note that this will still require updating jQuery to 1.7.1

We can send you an internal build once the fix is ready, if you want to try it out.

Regards,
Tsvetomir Tsonev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Tim
Top achievements
Rank 1
answered on 26 Jan 2012, 09:43 PM
After developing against IE 9 for 4 weeks, I started regression testing with IE8 and was just bitten by this event firing 2x issue.  Is there a scheduled date for the service release or a workaround?  I need to have file uploads working in 3 weeks and would hate to scrap this control due to this bug.
0
Georgi Tunev
Telerik team
answered on 27 Jan 2012, 03:48 PM
Hi Tim,

 I attached the latest build - I hope this helps.

Kind regards,
Georgi Tunev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Tim
Top achievements
Rank 1
answered on 27 Jan 2012, 08:50 PM
Unfortunately the provided hot fix did not seem to work for me...  I replaced the content and scripts folders with the new version, updated the reference to the hotfix'd Terlrik dll, and changed 2 script includes in my layout to use the new Telerik scripts version folder (using script tag in head instead of ScriptRegistrar due to load sequence issues with other jquery)...

However,  I am now working... When the fix didn't work and the Upload_to_database sample project worked even when updated to the 2011.3.1115 version, I tried a more drastic debugging technique...  I took my entire MVC Razor view and removed everything but  the upload control and it worked fine...  Then I put the page back and emptied my OnDocumentReady function...  Still worked in IE.  Added lines back one by one and found that it was related to the onchange event of a textbox that caused the issue (along the lines of the above JQuery bug reference...)  I found that :

$("#Amount").live('change', Amount_OnChange);


caused the double event, but

$(".LineAmount").change(function () { LineAmount_OnChange(this) });


did not...

I changed the first wiring from the .live to the .change syntax and now the upload control does not appear to be double-firing the events anymore in IE8...

Thanks again for the help, and hopefully the above JQuery syntax change will help others too...
Tags
Upload
Asked by
David
Top achievements
Rank 1
Iron
Answers by
Georgi Tunev
Telerik team
David
Top achievements
Rank 1
Iron
storyr
Top achievements
Rank 1
T. Tsonev
Telerik team
SUNG
Top achievements
Rank 1
Tim
Top achievements
Rank 1
Share this question
or