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

How to avoid IO Exception when using RadAsyncUpload

1 Answer 304 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 25 Jan 2018, 10:50 PM

Only occasionally I am receiving the "IOException: The process cannot access the file 'file path' because it is being used by another process".

How can I handle my upload to avoid encountering this error?

Here's my code example.

On the webform page.

                            <telerik:RadAsyncUpload
                                runat="server"
                                ID="fileUpload"
                                ChunkSize="3145728"
                                MaxFileInputsCount="1"
                                AllowedFileExtensions=".htm,.html,.HTML,.doc,.DOC,.docx,.zip,.txt,.mht,.MHT,.msg,.mp4,.pdf,.PDF"
                                OnClientValidationFailed="uploadValidationFailed">
                            </telerik:RadAsyncUpload>
                            <telerik:RadProgressArea
                                runat="server"
                                ID="RadProgressAreaTechNotes">
                            </telerik:RadProgressArea>

Codebehind

                    foreach (UploadedFile file in fileUpload.UploadedFiles)
                    {
                        uploadedFilename = file.FileName;
                        asyFileExtension = file.GetExtension().Replace(".", string.Empty);
                        asyFileSize = file.ContentLength;
                        string spath = storePath + uploadedFilename;

                        file.SaveAs(spath);
                    }

 

 

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 30 Jan 2018, 02:59 PM

Hi Andrew,

Based on this information, my best guess is that the file.SaveAs() call is causing the issue because there is something wrong with the permissions in the folder (e.g., the user of the application pool does not have the correct permissions to write/modify files there). This can apply both to the temporary folder the async upload uses, or to the destination folder that the save attempt targets.

In general, the error "The process cannot access the file because it is being used by another process" is usually caused when:

  • The uploaded file is read only.
  • The uploaded file is opened or used by another process.
  • Target and Temporary folders are read only or your application does not have write permissions to them.

We have also had a report that a Windows Update causes such an error from August 2017, even though we were never able to reproduce this: https://www.telerik.com/forums/the-process-cannot-access-the-file-because-it-is-being-used-by-another-process-7feefb30cd1b.

The final suggestions I can offer is that you try using the stream directly and to ensure it gets closed via an using statement: https://www.telerik.com/forums/read-file-data-from-asyncupload#RlGlGiCU5UCygCoS9D_FuQ and ensure that the destination path is not the same as the source path: https://www.telerik.com/forums/ioexception-when-saving#keu--TJVf0OfosIKpkujIQ.

Regards,

Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
AsyncUpload
Asked by
Andrew
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or