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

Not getting UploadedFiles.Count although file is attached to RadAsyncUpload

2 Answers 360 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Sweta
Top achievements
Rank 1
Sweta asked on 09 Apr 2012, 03:53 PM
I am using RadAsyncUpload control to upload the single file on button click. But when I hit the button, RadAsyncUpload.UploadedFiles.Count always says 0. Below is my code.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="QuestionDesigner.aspx.cs"
    MasterPageFile="~/Enigma/Masters/Main.master" Inherits="Enigma_QuestionDesigner"
    EnableEventValidation="false" ValidateRequest="false" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="Server">
     <Scripts>
           <asp:ScriptReference Path="~/Enigma/Telerik/Scripts/Common/Core.js" />
            <asp:ScriptReference Path="~/Enigma/Telerik/Scripts/Upload/RadProgressManager.js" />
            <asp:ScriptReference Path="~/Enigma/Telerik/Scripts/Common/jQuery.js" />
            <asp:ScriptReference Path="~/Enigma/Telerik/Scripts/Common/jQueryPlugins.js" />
            <asp:ScriptReference Path="~/Enigma/Telerik/Scripts/Upload/RadUpload.js" />
            <asp:ScriptReference Path="~/Enigma/Telerik/Scripts/AsyncUpload/RadAsyncUploadScripts.js" />
            <asp:ScriptReference Path="~/Enigma/Telerik/Scripts/Common/Popup/PopupScripts.js" />
            <asp:ScriptReference Path="~/Enigma/Telerik/Scripts/Upload/RadProgressArea.js" />
     </Scripts>
</asp:ScriptManager>
 
<asp:UpdatePanel ID="upQuestionSection" runat="server" UpdateMode="Conditional">    
        <ContentTemplate>
            <div>
                 <telerik:RadAsyncUpload ID="fileNodeDefinition" runat="server" MaxFileInputsCount="1"
                            AllowedFileExtensions=".xml" MaxFileSize="52428800">
                 </telerik:RadAsyncUpload>
            </div>
    </ContentTemplate>
</asp:UpdatePanel>
 
</asp:Content>
 
 
Below is Cs File Code
 
public void btnSave_Click(object sender,EventArgs e)
    {
        string filePath;
        if (fileNodeDefinition.UploadedFiles.Count > 0)
        {
                string file = fileNodeDefinition.UploadedFiles[0].FileName;
                filePath = HttpContext.Current.Server.MapPath(".\\Upload\\") + file;
                fileNodeDefinition.UploadedFiles[0].SaveAs(filePath);               
                fileNodeDefinition.UploadedFiles.Clear();
                fileNodeDefinition = null;               
            }
    }

Thanks & Regards,
Sweta Chotalia

2 Answers, 1 is accepted

Sort by
0
Sweta
Top achievements
Rank 1
answered on 10 Apr 2012, 11:40 AM
I have found solution for this issue. In RadAsyncUpload, you need to add property HttpHandlerUrl as below :

<telerik:RadAsyncUpload ID="fileNodeDefinition" HttpHandlerUrl="~/CustomHandler.ashx"
runat="server" MaxFileInputsCount="1" AllowedFileExtensions=".xml"></telerik:RadAsyncUpload>                                                        

Below is the code of HttpHandler file that you need to add to project :

<%@ WebHandler Language="C#" Class="CustomHandler" %>
 
using System;
using System.Web;
using Telerik.Web.UI;
 
public class CustomHandler : AsyncUploadHandler
{
    protected override IAsyncUploadResult Process(UploadedFile file, HttpContext context, IAsyncUploadConfiguration configuration, string tempFileName)
    {
        configuration.TimeToLive = TimeSpan.FromHours(4);
        return base.Process(file, context, configuration, tempFileName);
    }
 
}

0
Rubiya
Top achievements
Rank 1
answered on 28 May 2017, 06:03 AM

I have used the solution of HttpHandlers in my project as well as suggested in this post. However it still is not working for me.

My Async upload Control,(.aspx)

<telerik:RadAsyncUpload ID="radUpload" runat = "server" Skin = "Silk" Width="430px" MaxFileInputsCount="5" PostbackTriggers="btnSubmit" HttpHandlerUrl="~/CustomHandler.ashx"></telerik:RadAsyncUpload>

 

.aspx.cs

 

foreach (UploadedFile file in radUpload.UploadedFiles)
                {
                    fileName = file.FileName;
                    targetFolder = Server.MapPath("~/Development/Uploads/VOC");
                    if (!Directory.Exists(targetFolder))
                    {
                        Directory.CreateDirectory(targetFolder);
                    }
                    //fileNamefinal = fileName.Split('.')[0] + "_VOC." + fileName.Split('.')[1];
                    file.SaveAs(Path.Combine(targetFolder, fileName.Split('.')[0]+"_VOC."+fileName.Split('.')[1]));
                    fileNamefinal += "," + fileName.Split('.')[0] + "_VOC." + fileName.Split('.')[1];
                }

 

my Handler Class

 

using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using Telerik.Web.UI;

namespace EP.Web
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class CustomHandler : AsyncUploadHandler
    {

        //public void ProcessRequest(HttpContext context)
        //{
        //    context.Response.ContentType = "text/plain";
        //    context.Response.Write("Hello World");
        //}
        protected override IAsyncUploadResult Process(UploadedFile file, HttpContext context, IAsyncUploadConfiguration configuration, string tempFileName)
        {
            configuration.TimeToLive = TimeSpan.FromHours(4);
            return base.Process(file, context, configuration, tempFileName);
        }

        //public bool IsReusable
        //{
        //    get
        //    {
        //        return false;
        //    }
        //}
    }
}

I have added the following in web.config.
 <add path="*" type="EP.Web.CustomHandler" validate="false" verb="*"/>

Is there something that I am missing?Even after doing all this the Uploaded File Count is returning 0

 

Tags
AsyncUpload
Asked by
Sweta
Top achievements
Rank 1
Answers by
Sweta
Top achievements
Rank 1
Rubiya
Top achievements
Rank 1
Share this question
or