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

Intermittent error when uploading files larger than 1MB

4 Answers 121 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Courtlandt Harris
Top achievements
Rank 1
Courtlandt Harris asked on 25 Jan 2010, 07:23 PM
I recently updated the Telerik Silverlight DLL files for a project from 2009 Q2 to the Q3 release (most recent at present).  Previously the RadUpload control worked fine with the upload handler that I had created.  Upon updating the DLL files, all uploads worked perfectly when running locally in a development environment.  Once the control was moved onto the production server, however, files that were roughly 1MB in size or larger have begun to error out on an intermittent basis with the following error message:

"Cannot save the file: [The process cannot access the file '<<Insert file name here>>' because it is being used by another process.]"

The following are the essentials of the upload handler.  While I would love to think that the failure is my own faulty coding in the upload handler and that I might come across a solution rapidly by way of correcting my own errors, I don't believe this to be the case.  I have implemented the process shown below in several different manners through overriding several different base functions.  All error out the same.  Eventually, I went ahead and just used all base processes with no overridden code and the same errors persisted.

using Telerik.Windows.Controls; 
using System.Collections.Generic; 
using System.Data.SqlClient; 
using System.IO; 
using System; 
 
public class RadUploadHandler : Telerik.Windows.RadUploadHandler, System.Web.SessionState.IRequiresSessionState 
 
    public override string TargetPhysicalFolder 
    { 
        get 
        { 
            string BatchID = "9" + DateTime.Now.Year.ToString() + Right("0" + DateTime.Now.Month.ToString(), 2); 
            return Context.Server.MapPath("~\\") + "files\\" + BatchID; 
        } 
    } 
     
    public override void ProcessStream() 
    { 
 
         
        if (this.IsNewFileRequest()) 
        { 
 
            if (!Directory.Exists(TargetPhysicalFolder)) 
            { 
                //Create Directory 
                Directory.CreateDirectory(TargetPhysicalFolder); 
            } 
             
        } 
         
        base.ProcessStream(); 
         
        if (this.IsFinalFileRequest()) 
        { 
            try
            {
           
               /* The omitted code performs database updates pertinent only to the
               specific business application of the control */ 
 
            } 
            catch (Exception ex) { Context.Session["error"] = ex.Message; } 
 
            try 
            { 
                File.Move(Context.Server.MapPath("~\\") + "files\\" + BatchID.ToString() + "\\" + oldFileName, Context.Server.MapPath("~\\") + "files\\" + BatchID.ToString() + "\\" + fileName); 
            } 
            catch (Exception ex) { Context.Session["error"] = ex.Message; } 
                 
        } 
             
    }  

I also am rather certain that the error is not dealing with any code pertaining to the last chunk of data as the .IsFinalFileRequest() method call is not reached.  If it were, the first event to occur would be a database update that wouldn't error out.  The update doesn't occur, and, just in case, when capturing any errors in the database updates in a try-catch, none are captured.  Therefore, it is safe to conclude (I think) that the error has nothing to do with the final chunk of data.

The only other relevant information that I can give is that the control has been styled to mimic the WebBlue theme from the ASP.NET controls.  I don't see how this could or would affect anything, but I've been wrong before...

The final bit of testing that I did was to revert the RadUploadHandler.dll file to its Q2 and Q1 versions.  Both produced the same error.

Is there an error that I am making that I am not thinking of, or is this possibly a bug in the Q3 upload control?

4 Answers, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 27 Jan 2010, 10:02 AM
Hi Courtlandt,

Thank you for contacting us.

The reported case sounds very strange. We found your code is OK. Are there something else: more code in your handler or an Anti-virus program on the server?

Could you try the upload without any sophisticated parts. Please try and tell us how the basic upload handler works on your server.

Looking forward for your reply.

Greetings,
Ivan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Courtlandt Harris
Top achievements
Rank 1
answered on 27 Jan 2010, 04:08 PM
Ivan,

Thank you for your reply.  Your suggestion about anti-virus software was a great jump off point.  I tested uploading with it turned off, and while the anti-virus software isn't the issue, it seems that the Windows indexing service is.  Since the file is uploaded in chunks and the file stream closed and reopened after each chunk (from what I can gather), some system process is accessing the file during the upload.  This is almost certainly the indexing service as all directories that files are uploaded to are automatically indexed for text-searching.  This also would account for the intermittent nautre of the problem and explain why it does not occur locally.

As a follow up note to my previous posting, it has nothing to do with the version of any controls, I went back and more thoroughly tested older versions and the issue remains the same.  I am going to try uploading the file with an unknown extension, such as ".upload", and if that doesn't prevent the indexing service from accessing the file, then perhaps overriding the SaveChunkData() and saving the chunks with a filestream that is saved to a session variable and remains open until the last chunk is uploaded  would solve the problem.

I'll let you know which solution ends up working.  Feel free to suggest any others that come to mind.

Thank you for the response.

Peace,
Courtlandt
0
Courtlandt Harris
Top achievements
Rank 1
answered on 27 Jan 2010, 04:37 PM
The first, and likely much simpler, solution of using an unknown file extension (.upload) while uploading solved the problem.  I didn't attempt the second thought of maintaining an open file stream, so I can't comment as to how that idea would work.

Thank you for your help.
0
Ivan
Telerik team
answered on 27 Jan 2010, 05:03 PM
Hi Courtlandt,

Thank you for sharing your experience with us.

Uploading a file into a file stream will not work because we are uploading each chunk in a separate post request. However uploading files with different names (i.e. different extension) is already demonstrated in our online articles especially. Please preview them and if you have more questions just drop us a line.
 

Kind regards,
Ivan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Upload
Asked by
Courtlandt Harris
Top achievements
Rank 1
Answers by
Ivan
Telerik team
Courtlandt Harris
Top achievements
Rank 1
Share this question
or