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

2 posts, 0 answers
  1. zykes
    zykes avatar
    2 posts
    Member since:
    Jun 2011

    Posted 03 Dec 2013 Link to this post

    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);
        }
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 Dec 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top