OnFileUploaded not firing

3 posts, 0 answers
  1. Vance Smith
    Vance Smith avatar
    36 posts
    Member since:
    Jun 2012

    Posted 30 Oct 2013 Link to this post

    Hi,

    The OnFileUploaded event is not firing. Am i missing something?

    aspx

    <telerik:RadCloudUpload 
                            ID="CU" 
                            runat="server" 
                            MultipleFileSelection="Disabled" 
                            ProviderType="Azure" 
                            MaxFileSize="2147483648"
                            OnFileUploaded="CU_FileUploaded"
                            OnClientUploadFailed="OnClientUploadFailed" 
                            AllowedFileExtensions=".pdf"
                            httpHandlerUrl="~/AzureUploadHandler.ashx">
                        </telerik:RadCloudUpload>

    aspx.cs

     protected async void AU_FileUploaded( object sender, Telerik.Web.UI.FileUploadedEventArgs e ) {
                DateTime startDate = DateTime.Now;
                Bll.BfxFiles.SaveFileAsync( Sys.Config.DomainId, 0, 1, e.File.InputStream, e.File.FileName );

                AsyncUploadLabel.ForeColor = System.Drawing.Color.Green;
                AsyncUploadLabel.Text = string.Format( "File '{0}' uploaded successfully to Azure BLOB storage.<br/>Start: {1}<br/>End: {2}<br/>Size: {3}", 
                    e.File.FileName, startDate.ToString(), DateTime.Now.ToString(), e.File.ContentLength.ToString() );
            }

    handler

    <%@ WebHandler Language="C#" Class="AzureUploadHandler" %>

    using System;
    using System.Web;

    public class AzureUploadHandler : Telerik.Web.UI.CloudUploadHandler, System.Web.SessionState.IReadOnlySessionState {
        
        public override void SetKeyName(object sender, Telerik.Web.UI.CloudUpload.SetKeyNameEventArgs e) {
            if ( HttpContext.Current.Session["SelectedBfxFileId"] == null ) {
                HttpContext.Current.Response.Redirect( "~/Login.aspx?m=1" ); // session timed out
            }
            else {
                try {
                    int bfxFileId = Convert.ToInt32(  HttpContext.Current.Session["SelectedBfxFileId"] );
                    if ( bfxFileId == 0 ) {
                        HttpContext.Current.Response.Redirect( "~/Error.aspx?e=1" ); // invalid bfxFileId
                    }
                    else {
                        e.KeyName = Bll.BfxFiles.BuildBlobName( bfxFileId, e.OriginalFileName );
                    }
                }
                catch ( Exception ex ) {
                    throw ex;
                }
            }
        }
    }
  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 01 Nov 2013 Link to this post

    Hi Vance,

    This event will be fired after you cause a postback. Also I have noticed that there is a typo in your markup:
    <telerik:RadCloudUpload
                            ID="CU"
                            runat="server"
                            MultipleFileSelection="Disabled"
                            ProviderType="Azure"
                            MaxFileSize="2147483648"
                            OnFileUploaded="CU_FileUploaded"
                            OnClientUploadFailed="OnClientUploadFailed"
                            AllowedFileExtensions=".pdf"
                            httpHandlerUrl="~/AzureUploadHandler.ashx">
                        </telerik:RadCloudUpload>

    protected async void AU_FileUploaded( object sender, Telerik.Web.UI.FileUploadedEventArgs e ) {
               DateTime startDate = DateTime.Now;
               Bll.BfxFiles.SaveFileAsync( Sys.Config.DomainId, 0, 1, e.File.InputStream, e.File.FileName );
     
               AsyncUploadLabel.ForeColor = System.Drawing.Color.Green;
               AsyncUploadLabel.Text = string.Format( "File '{0}' uploaded successfully to Azure BLOB storage.<br/>Start: {1}<br/>End: {2}<br/>Size: {3}",
                   e.File.FileName, startDate.ToString(), DateTime.Now.ToString(), e.File.ContentLength.ToString() );
           }

    Could this be the reason for not firing?

    Regards,
    Hristo Valyavicharski
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Eric
    Eric avatar
    13 posts
    Member since:
    Jan 2013

    Posted 01 Nov 2013 Link to this post

    Hi Vance,

    You can automatically trigger a postback when the upload finishes by capturing the OnClientFilesUploaded JavaScript event.  That should make fire off the event handler.

    Otherwise, add a button that appears, which says something like "Save Uploads" or something. That would also trigger the server side event.

    -Eric
Back to Top