How to set OnFileUploaded dynamically?

3 posts, 0 answers
  1. Troy
    Troy avatar
    9 posts
    Member since:
    Feb 2013

    Posted 11 Jul 2013 Link to this post

    I have a RadAsyncUpload control that is declared dynamically on the server side.  It is working fine.  However, I would like to change the filename before it is saved.  I tried to set the OnFileUploaded property, but I get the message

    'Telerik.Web.UI.RadAsyncUpload.OnFileUploaded (Telerik.Web.UI.FileUploadedEventArgs)' is inaccessible due to its protection level.

    How do I set the OnFileUploaded property?  Alternatively, how else could I change the file name of the file before saving it to the sever?

    Here is where I declare the RadAsyncUpload control:
    RadAsyncUpload upload = new RadAsyncUpload();
    upload.ID = "rauChoice";
    upload.Attributes.Add("runat", "server");
    upload.TargetFolder = "~/App_Images/uploads";
    upload.TemporaryFolder = "~/App_Data/RadUploadTemp";
    upload.OnFileUploaded = "rauChoice_FileUploaded";
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Jul 2013 Link to this post

    Ho Troy,

    You cannot attach the OnFileUploaded server side event like this. upload.OnFileUploaded="rauChoice_FileUploaded". Please have a look at the following code I tried which works fine at my end.

    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        RadAsyncUpload upload = new RadAsyncUpload();
        upload.ID = "rauChoice";
        upload.Attributes.Add("runat", "server");
        upload.TargetFolder = "~/Images/Img/";
        upload.FileUploaded += new FileUploadedEventHandler(upload_FileUploaded);
        this.form1.Controls.Add(upload);
    }
     
    void upload_FileUploaded(object sender, FileUploadedEventArgs e)
    {
        RadAsyncUpload upload1 = sender as RadAsyncUpload;
        string targetfolder = upload1.TargetFolder;
        //your code to rename file
        e.File.SaveAs(Path.Combine(Server.MapPath(targetfolder), "UpdatedFileName"));
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Troy
    Troy avatar
    9 posts
    Member since:
    Feb 2013

    Posted 15 Jul 2013 Link to this post

    Thank you!  This worked great.
Back to Top