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

overrides not being hit

1 Answer 39 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Nick Wood
Top achievements
Rank 1
Nick Wood asked on 14 Jan 2016, 08:06 AM

Hi All

I amusing the RadUploadHandler and overriding certain methods in my .ahsx file but these methods never seem to be hit.

In the below code no file names are changed, no new directories are created. The file is still uploaded to the root of the target directory fine, but same filename as source.

public class DocumentRequiredUploadHandle : RadUploadHandler
    {
 
        private string newFileName = string.Empty;
 
        //Upload Parameters
        private string OppId = string.Empty;
        private string ClientName = string.Empty;
        private string FileNamePrefix = string.Empty;
        private string DirLoc = string.Empty;
 
        public override Dictionary<string, object> GetAssociatedData()
        {
            Dictionary<string, object> dict = base.GetAssociatedData();
            if (!string.IsNullOrEmpty(newFileName))
            {
                dict.Add("NewFileLocation", this.newFileName);
            }
            return dict;
        }
 
        public override bool SaveChunkData(string filePath, long position, byte[] buffer, int contentLength, out int savedBytes)
        {
            return base.SaveChunkData(filePath, position, buffer, contentLength, out savedBytes);
        }
 
        public override string GetFilePath(string fileName)
        {
            OppId = this.GetQueryParameter("OppId");
            ClientName = this.GetQueryParameter("ClientName");
            FileNamePrefix = this.GetQueryParameter("FileNamePrefix");
            DirLoc = this.TargetPhysicalFolder + @"\" + OppId;
            if (!Directory.Exists(DirLoc))
            {
                Directory.CreateDirectory(DirLoc);
            }
 
            string FilePath = string.Format(@"{0}\{1}", DirLoc, this.GetFileName(fileName));
            return FilePath;
        }
 
        private string GetFileName(string fileName)
        {
            if (this.IsNewFileRequest())
            {
                this.ResultChunkTag = string.Format("{0} {1} {2}", FileNamePrefix, ClientName, DateTime.Now.ToString("yyyyMMdd_hhmmss"));
            }
            else if (this.FormChunkTag != null)
            {
                this.ResultChunkTag = this.FormChunkTag;
            }
 
            if (this.ResultChunkTag != null)
            {
                int i = fileName.LastIndexOf('.');
                if (i >= 0)
                {
                    fileName = string.Format("{0}.{1}", this.ResultChunkTag, fileName.Substring(i + 1));
                }
            }
            return this.newFileName = fileName;
        }
    }

Regards

Nick wood

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 18 Jan 2016, 01:35 PM
Hi Nick,

I tested the code of the handler from your last reply but I wasn't able to reproduce the described issue. All the overridden methods are called as expected. You can try the following to resolve this:
  • Close Visual Studio. Manually delete the bin and obj folders of the projects which contains the RadUpload control. Then open VS and Clean, and Rebuild the solution. This should clear all cached files.
  • Create a new project with RadUpload and the same handler, and see if the issue still appears.

I hope this helps.

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Upload
Asked by
Nick Wood
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or