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

Index out of range when using RadAsyncUpload

2 Answers 54 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Charlie
Top achievements
Rank 1
Charlie asked on 22 Sep 2011, 09:01 AM
Hi,

I use RadAsyncUpload along with custom handler to upload files to FTP but occasionally got the following errors and really don't understand how this happened. The stack trace of the error is as follows.

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


at System.Collections.ArrayList.get_Item(Int32 index)
at Telerik.Web.UI.AsyncUpload.RequestData..ctor(HttpContext context)
at Telerik.Web.UI.AsyncUploadHandler.EnsureSetup()
at Telerik.Web.UI.AsyncUploadHandler.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


Any ideas?

Thanks,
Charlie

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 23 Sep 2011, 06:20 PM
Hello,

Please provide your code(C#) so i can check.

Thanks,
Jayesh Goyani
0
Charlie
Top achievements
Rank 1
answered on 30 Sep 2011, 09:30 AM
Hi,

The handler is as follows.

protected
override IAsyncUploadResult Process(UploadedFile file, HttpContext context, IAsyncUploadConfiguration configuration, string tempFileName)
    {
        Portal.FileConfigResult oResult = CreateDefaultUploadResult<Portal.FileConfigResult>(file);
 
        Portal.FileConfig oConfig = configuration as Portal.FileConfig;
         
        Util.FTP oFTP = new Util.FTP();
        oResult.FileSize = Util.Functions.FormatFileSize(file.ContentLength);
         
        string sFTPUrl = System.Configuration.ConfigurationManager.AppSettings["FTPUrl"];
        string sFolder = "";
        string sFilename = "";
         
        try
        {
            //check if file name contains invalid characters
            System.Text.RegularExpressions.MatchCollection arrMatch = System.Text.RegularExpressions.Regex.Matches(file.GetName(), @"[\u3300-\u9fff\uf900-\ufaff]+");
 
            //validate the file
            //the max length of filename is 75 characters
            //filename does not support chinese characters
            if (file.GetName().Length > 75 || arrMatch.Count > 0)
            {
                oResult.FilePath = "";
                oResult.UploadedBy = "";
                oResult.FileName = "";
                oResult.UploadedDate = "";
                return oResult;
            }
 
            sFilename = file.GetNameWithoutExtension();      
            sFilename = sFilename + file.GetExtension();
         
            oFTP.FTPUpload(file.InputStream, sFTPUrl, sFilename);
 
            oResult.FilePath = oFTP.Folder + "/" + oFTP.ReNameFileName;
            if (string.IsNullOrEmpty(oConfig.UploadedBy))
            {
                oResult.UploadedBy = context.Profile.GetPropertyValue("FirstName") + " " +
                                     context.Profile.GetPropertyValue("LastName");
            }
            else
            {
                oResult.UploadedBy = oConfig.UploadedBy;
            }
            //get new file name
            oResult.FileName = oFTP.ReNameFileName;
         
            oResult.UploadedDate = DateTime.Today.ToString("yyyy/MM/dd");
 
        }
        catch (Exception ex)
        {
            Util.ErrorHandler oErr = new Util.ErrorHandler();
            oErr.SetErrorDescription(ex);
             
            oErr.WriteErrorLog();
        }
         
        return oResult;   
    }
Tags
AsyncUpload
Asked by
Charlie
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Charlie
Top achievements
Rank 1
Share this question
or