MoveTo throws an exception

Last post 05-30-2013, 12:15 PM by Kenneth. 7 replies.
Sort Posts: Previous Next
  •  05-24-2013, 4:57 AM 77480

    MoveTo throws an exception

    Hello,

     

    When I try to save an uploaded file using the MoveTo method, I get the following IOException:

     

    "Cannot create a file when that file already exists."

     

    The folder I am trying to save the file to is empty! I tried passing both absolute and relative paths to the method, but to no avail. What is the problem?

     

    Thanks. 

  •  05-24-2013, 12:31 PM 77483 in reply to 77480

    Re: MoveTo throws an exception

    Hi Ardalan,

     

    Can you try another store folder? Does it get the same problem?

     

    Can you show me the full code what you are testing?

     

    Regards,

     

    Ken 

  •  05-28-2013, 6:53 AM 77492 in reply to 77483

    Re: MoveTo throws an exception

    Hi Ken,

     

    I tried a different folder and got the same exception. Here is the ASPX code:

     

    <CuteWebUI:UploadAttachments runat="server" ID="MultiFileUploader"
                    InsertText="Add a File"
                    onfileuploaded="MultiFileUploader_FileUploaded">

    <asp:Button ID="AskButton" runat="server" Text="Ask Question"
                    onclick="AskButton_Click" /> 

     

    The part of the code-behind related to the uploader:

     

    private List<Guid> FileGuids {
                get {
                    if (ViewState["Guids"] == null)
                        ViewState["Guids"] = new List<Guid>();
                    return ViewState["Guids"] as List<Guid>;
                }
            }

     

    protected void MultiFileUploader_FileUploaded(object sender, CuteWebUI.UploaderEventArgs args) {
                FileGuids.Add(args.FileGuid);
            }

     

     protected void AskButton_Click(object sender, EventArgs e) {
                

                // Save Files
                foreach (Guid g in FileGuids) {
                    MvcUploadFile f = MultiFileUploader.GetUploadedFile(g);
                    f.MoveTo(ControlPath);
                }

               
            }

     

    I save the file GUIDs because I need to save the files when the Ask Button is clicked, not after each file is uploaded. However, I also tested moving the MoveTo method  to the FileUploaded event but got the same exception again.

  •  05-28-2013, 12:11 PM 77498 in reply to 77492

    Re: MoveTo throws an exception

    Hi Ardalan,

     

    Can you debug it and show me which line causes this error?

     

    Regards,

     

    Ken 

  •  05-29-2013, 4:58 AM 77500 in reply to 77498

    Re: MoveTo throws an exception

    I have included a screenshot of the debugger. Let me know if you need any other information.

     

     

  •  05-29-2013, 12:12 PM 77503 in reply to 77500

    Re: MoveTo throws an exception

    Hi Ardalan,

     

    I think the problem is your FileGuids, all the guid save as the same value, so it try to save the same file multiple times.

     

    Debug the foreach loop, check the first guid, second guid, is the same guid? 

     

    Regards,

     

    Ken 

  •  05-30-2013, 3:05 AM 77509 in reply to 77503

    Re: MoveTo throws an exception

    The exception is thrown on the first file. The files have different GUIDs, as you can see in the screenshot.
  •  05-30-2013, 12:15 PM 77513 in reply to 77509

    Re: MoveTo throws an exception

    Hi Ardalan,

     

    If replace the method to "CopyTo", does it work? Is your site online? If so, can you set up ftp access for us? So we can check the code for you directly.

     

    Try save the files in the handler file "UploadHandler.ashx" directly, does it work?

     

    the handler file has a method  "public override void OnFileUploaded(MvcUploadFile file)", you can save the file there. 

     

    Regards,

     

    Ken 

View as RSS news feed in XML