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

FileNotFoundException

3 Answers 70 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 17 Jan 2013, 03:37 PM
I am using RadAsyncUpload and cannot get it to work with more than one file.  

Basically, I'm using the FileUploaded event to save the file as a different filename (using a GUID) to ensure uniqueness.

This is what i am seeing (an example that I stepped through):

1. I upload two files on my form
2. After selecting the files and the status says they are complete, they are in the App_Data\Uploasd folder as:

fvcjn4uc.ls0
RadUploadTestFile
skhgx0p0.0at

3. I post the page

4. I step through and let it go through the first file, and it works, and I see that fvcjn4uc.ls0 is removed from App_Data\Uploads (e.g. only skhgx0p0.0at and RadUploadTestFile remains).

5. I then go through the next item in the foreach loop and it can access the filename and extension fine but when it does e.File.SaveAs(newFilename) I get (full path removed w/"HIDDEN"):

Could not find file 'C:\TFS\2010\[HIDDEN]\App_Data\Uploads\fvcjn4uc.ls0'.

But that's the filename of the FIRST file that was removed, why is it trying to access this again?
   
Code:


        protected void RadAsyncUploadAttachments_FileUploaded(object sender, FileUploadedEventArgs e)
        {
            try
            {
                foreach (UploadedFile newfile in RadAsyncUploadAttachments.UploadedFiles)
                {
                    if (newfile != null)
                    {
                        string originalFilename = newfile.FileName;
                        string filename = Guid.NewGuid().ToString() + newfile.GetExtension();
                        string newFilename = RadAsyncUploadAttachments.TargetFolder + @"\" + filename;

                        e.File.SaveAs(newFilename);
                    }
                }
            }

            catch (Exception ex)
            {
                log.Error(ex);
            }
        }      

What am I missing?

Thanks,

Dave

3 Answers, 1 is accepted

Sort by
0
Accepted
Plamen
Telerik team
answered on 22 Jan 2013, 11:13 AM
Hello Dave,

 
Thank you for contacting Telerik support.

I have inspected the code provided. It seems that the issue is caused because of the "foreach" function itself -you actually do not need it because OnFileUploaded is fired for every uploaded file separately.

Hope this will explain the issue. If you have further questions please don't hesitate to contact us again.

Regards,
Plamen
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 RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Dave
Top achievements
Rank 1
answered on 22 Jan 2013, 01:50 PM
Ok, that makes sense, I thought it fired once but after reading this that wouldn't make any sense.   I'll my my adjustments and test and post my results.  Thanks.

0
Dave
Top achievements
Rank 1
answered on 22 Jan 2013, 02:18 PM
That was it.  I was able to get this to work now.

Thanks for your help.

Tags
AsyncUpload
Asked by
Dave
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Dave
Top achievements
Rank 1
Share this question
or