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

The process cannot access the file because it is being used by another process.

1 Answer 544 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
zykes
Top achievements
Rank 1
zykes asked on 03 Dec 2013, 06:08 AM
Hi,

Im uploading a file using RadAsyncUpload control and I wanted to check if the image to be uploaded is really image, not just another file changed of extension name. Code below:

The error is triggered on the .SaveAs() function

            String fileExt = rfile_image.UploadedFiles[0].FileName.Substring(rfile_image.UploadedFiles[0].FileName.LastIndexOf('.') + 1).ToUpper();
            byte[] tmp = imageHeader[fileExt];
            byte[] header = new byte[tmp.Length];
            rfile_image.UploadedFiles[0].InputStream.Read(header, 0, header.Length);
            
            if (!CompareArray(tmp, header))
            {
                //invalid content type
                rfile_image.Dispose();
                rfile_image.UploadedFiles[0].InputStream.Close();
                rfile_image.UploadedFiles[0].InputStream.Dispose();
                
                returnError("Filename Invalid");
            }
            else
            {
                //valid content type, continue with saving
                fileUrl = "C:\\data\\" + fileWithPath;                
              
                rfile_image.UploadedFiles[0].SaveAs(fileUrl,true);
    }

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Dec 2013, 02:19 PM
Hi zykes,

Try closing the stream rfile_image.UploadedFiles[0].InputStream.close() before attempting to save the file. Please have a look into this forum thread which deals with a similar scenario.

Hope this helps,
Shinu.
Tags
AsyncUpload
Asked by
zykes
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or