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

OnClientProgressUpdating

4 Answers 140 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Piotr
Top achievements
Rank 1
Piotr asked on 20 Oct 2009, 01:28 PM
Hi, I've got a problem with checking file size on upload. There is not RadUpload object in arguments so line in checkUploadedFilesSize function with args.get_progressData().RadUpload.RequestSize generates error. I searched everywhere for solution, most info linked to
this site: http://www.telerik.com/help/aspnet-ajax/upload_howtoclientfilesize.html, but it doesn't help. I use 2009.2.701.35 version of library.
Here is my aspx markup:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title></title
</head> 
<body> 
    <form id="form1" runat="server"
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
        <Scripts> 
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" /> 
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" /> 
        </Scripts> 
    </telerik:RadScriptManager> 
    <div> 
 
        <script type="text/javascript"
            function checkUploadedFilesSize(progressArea, args) { 
                //progressArea.confirmed is a custom variable, 
                // you can use another if you want to 
                if (!progressArea.confirmed && 
       args.get_progressData().RadUpload.RequestSize > 1000000) { 
                    if (confirm("The total size of the selected files" + 
                 " is more than the limit." + 
                 " Do you want to cancel the upload?")) { 
                        progressArea.cancelRequest(); 
                    } 
                    else { 
                        progressArea.confirmed = "confirmed"
                    } 
                } 
            } 
        </script> 
 
        <telerik:RadUpload runat="server" ID="RadUpload1" /> 
        <telerik:RadProgressArea runat="server" ID="RadProgressArea1" OnClientProgressUpdating="checkUploadedFilesSize" /> 
        <telerik:RadProgressManager runat="server" ID="RadProgressManager1" /> 
        <asp:Button runat="server" ID="Button1" Text="Upload" OnClick="buttonSubmit_Click" /> 
    </div> 
    </form> 
</body> 
</html> 
 

here is my code behind code:
using System; 
 
using Telerik.Web.UI; 
using Telerik.Web.UI.Upload; 
 
public partial class Default : System.Web.UI.Page  
    protected void Page_Load(object sender, EventArgs e) 
    { 
            if (!IsPostBack) 
            { 
                //Do not display SelectedFilesCount progress indicator. 
                RadProgressArea1.ProgressIndicators &= ~ProgressIndicators.SelectedFilesCount; 
            } 
 
        } 
 
        protected void buttonSubmit_Click(object sender, System.EventArgs e) 
        { 
            UploadedFile file = RadUpload1.UploadedFiles[0]; //UploadedFile.FromHttpPostedFile(Request.Files[inputFile.UniqueID]); 
 
            if(!Object.Equals(file, null)) 
            { 
                LooongMethodWhichUpdatesTheProgressContext(file); 
            } 
        } 
 
        private void LooongMethodWhichUpdatesTheProgressContext(UploadedFile file) 
        { 
            const int total = 100
 
            RadProgressContext progress = RadProgressContext.Current; 
 
            for (int i = 0; i < total; i++) 
            { 
                progress.PrimaryTotal = 1
                progress.PrimaryValue = 1
                progress.PrimaryPercent = 100
 
                progress.SecondaryTotal = total
                progress.SecondaryValue = i
                progress.SecondaryPercent = i
 
                progress.CurrentOperationText = file.GetName() + " is being processed..."; 
 
                if (!Response.IsClientConnected) 
                { 
                    //Cancel button was clicked or the browser was closed, so stop processing 
                    break; 
                } 
 
                //Stall the current thread for 0.1 seconds 
                System.Threading.Thread.Sleep(100); 
            } 
        }    
 

and to be sure here is my web.config (it's more or less template from telerik project template)
<?xml version="1.0"?> 
<configuration> 
    <configSections> 
        <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
                <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
                <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
                    <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/> 
                    <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
                    <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
                    <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
                </sectionGroup> 
            </sectionGroup> 
        </sectionGroup> 
    </configSections> 
    <appSettings/> 
    <connectionStrings/> 
    <system.web> 
        <compilation debug="true"
            <assemblies> 
                <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> 
                <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
                <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> 
                <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> 
            </assemblies> 
        </compilation> 
        <pages> 
            <controls> 
                <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
                <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
                <add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI"/> 
            </controls> 
        </pages> 
        <authentication mode="Windows"/> 
        <httpHandlers> 
            <remove verb="*" path="*.asmx"/> 
            <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
            <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
            <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/> 
            <add path="ChartImage.axd" type="Telerik.Web.UI.ChartHttpHandler" verb="*" validate="false"/> 
            <add path="Telerik.Web.UI.SpellCheckHandler.axd" type="Telerik.Web.UI.SpellCheckHandler" verb="*" validate="false"/> 
            <add path="Telerik.Web.UI.DialogHandler.aspx" type="Telerik.Web.UI.DialogHandler" verb="*" validate="false"/> 
            <add path="Telerik.RadUploadProgressHandler.ashx" type="Telerik.Web.UI.RadUploadProgressHandler" verb="*" validate="false"/> 
            <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false"/> 
        </httpHandlers> 
        <httpModules> 
            <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
            <add name="RadUploadModule" type="Telerik.Web.UI.RadUploadHttpModule"/> 
            <add name="RadCompression" type="Telerik.Web.UI.RadCompression"/> 
        </httpModules> 
    <httpRuntime maxRequestLength="102400" executionTimeout="3600"/> 
  </system.web> 
    <system.codedom> 
        <compilers> 
            <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                <providerOption name="CompilerVersion" value="v3.5"/> 
                <providerOption name="WarnAsError" value="false"/> 
            </compiler> 
            <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                <providerOption name="CompilerVersion" value="v3.5"/> 
                <providerOption name="OptionInfer" value="true"/> 
                <providerOption name="WarnAsError" value="false"/> 
            </compiler> 
        </compilers> 
    </system.codedom> 
 
    <system.webServer> 
        <validation validateIntegratedModeConfiguration="false"/> 
        <modules> 
            <remove name="ScriptModule"/> 
            <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
            <add name="RadUploadModule" type="Telerik.Web.UI.RadUploadHttpModule"/> 
            <add name="RadCompression" type="Telerik.Web.UI.RadCompression"/> 
        </modules> 
        <handlers> 
            <remove name="WebServiceHandlerFactory-Integrated"/> 
            <remove name="ScriptHandlerFactory"/> 
            <remove name="ScriptHandlerFactoryAppServices"/> 
            <remove name="ScriptResource"/> 
            <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
            <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
            <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
            <add name="ChartImage_axd" path="ChartImage.axd" type="Telerik.Web.UI.ChartHttpHandler" verb="*" preCondition="integratedMode,runtimeVersionv2.0"/> 
            <add name="Telerik_Web_UI_SpellCheckHandler_axd" path="Telerik.Web.UI.SpellCheckHandler.axd" type="Telerik.Web.UI.SpellCheckHandler" verb="*" preCondition="integratedMode,runtimeVersionv2.0"/> 
            <add name="Telerik_Web_UI_DialogHandler_aspx" path="Telerik.Web.UI.DialogHandler.aspx" type="Telerik.Web.UI.DialogHandler" verb="*" preCondition="integratedMode,runtimeVersionv2.0"/> 
            <add name="Telerik_RadUploadProgressHandler_ashx" path="Telerik.RadUploadProgressHandler.ashx" type="Telerik.Web.UI.RadUploadProgressHandler" verb="*" preCondition="integratedMode,runtimeVersionv2.0"/> 
            <add name="Telerik_Web_UI_WebResource_axd" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" preCondition="integratedMode,runtimeVersionv2.0"/> 
        </handlers> 
    <security> 
      <requestFiltering> 
        <requestLimits maxAllowedContentLength="1024000000" /> 
      </requestFiltering> 
    </security> 
  </system.webServer> 
    <runtime> 
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"
            <dependentAssembly> 
                <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/> 
                <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/> 
            </dependentAssembly> 
            <dependentAssembly> 
                <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/> 
                <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/> 
            </dependentAssembly> 
        </assemblyBinding> 
    </runtime> 
</configuration> 

4 Answers, 1 is accepted

Sort by
0
Piotr
Top achievements
Rank 1
answered on 22 Oct 2009, 08:00 AM
Can anyone help me with my problem?
0
Genady Sergeev
Telerik team
answered on 22 Oct 2009, 03:42 PM
Hello Artur Lasota,

The way you monitor the progress is wrong. Please, remove the method called "LooongMethodThatUpgardes...". Such methods should be used only when monitoring custom progress. When monitoring file upload, all the work is done for you. There is no need to line single line of code in order to monitor the progress. You checkUploadedFilesSize function looks correct and it should start working when you remove the aforementioned method. For your convenience I have attached sample project that checks file size on the client.

Greetings,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Piotr
Top achievements
Rank 1
answered on 23 Oct 2009, 08:10 AM
Thank You, This method LooongMethodThatUpgardes was copied from Your site. I found it while searching for a solution. I don't really know how it works now but it does... Now it adds radupload instance in arguments of the event...
One more question. Is there any way to find out the size of each uploaded file? Now If I'm uploading couple of files RadUpload.RequestSize returns sum of sizes
0
Genady Sergeev
Telerik team
answered on 29 Oct 2009, 11:19 AM
Hello Artur Lasota,

You most probably have taken that method from the CustomProgress demo, it may work for a very small files, but my suggestion is to remove it and stick to the default upload monitor functionality. As for the uploaded files.

As for your question, you can use the ContentLength property of the UploadedFiles class in order to check the files size of the distinct files.

Best wishes,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Upload (Obsolete)
Asked by
Piotr
Top achievements
Rank 1
Answers by
Piotr
Top achievements
Rank 1
Genady Sergeev
Telerik team
Share this question
or