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

Maximum filesize

5 Answers 56 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Dick
Top achievements
Rank 1
Dick asked on 19 Sep 2011, 07:27 AM

We want to limit the upload filesize. We created a test project using samples on the telerikwebsite. When maximum filesize is reached an error is thrown. What am i doing wrong? Below the code:

ASPX

<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    <Scripts>
        <%--Needed for JavaScript IntelliSense in VS2010--%>
        <%--For VS2008 replace RadScriptManager with ScriptManager--%>
        <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" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
    </Scripts>
</telerik:RadScriptManager>
<script type="text/javascript">
    function checkUploadedFilesSize(progressArea, args) {
        alert("ok");
        //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" />

CS

protected void RadUpload1_FileExists(object sender, UploadedFileEventArgs e)
{
    UploadedFile file = e.UploadedFile;
 
    string targetFileName = Server.MapPath(RadUpload1.TargetFolder) + RadUpload1.UploadedFiles[0].GetName();
    file.SaveAs(Server.MapPath(@"Upload" + @"\" + targetFileName));
}


web.config

<?xml version="1.0"?>
<configuration>
    <appSettings>
        <add key="Telerik.ScriptManager.TelerikCdn" value="Disabled"/>
        <add key="Telerik.StyleSheetManager.TelerikCdn" value="Disabled"/>
    </appSettings>
    <system.web>
        <compilation debug="true" targetFramework="4.0"/>
        <pages>
            <controls>
                <add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI"/>
            </controls>
        </pages>
        <httpHandlers>
            <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="RadUploadModule" type="Telerik.Web.UI.RadUploadHttpModule"/>
            <add name="RadCompression" type="Telerik.Web.UI.RadCompression"/>
        </httpModules>
    </system.web>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules runAllManagedModulesForAllRequests="true">
            <remove name="RadUploadModule"/>
            <add name="RadUploadModule" type="Telerik.Web.UI.RadUploadHttpModule" preCondition="integratedMode"/>
            <remove name="RadCompression"/>
            <add name="RadCompression" type="Telerik.Web.UI.RadCompression" preCondition="integratedMode"/>
        </modules>
        <handlers>
            <remove name="ChartImage_axd"/>
            <add name="ChartImage_axd" path="ChartImage.axd" type="Telerik.Web.UI.ChartHttpHandler" verb="*" preCondition="integratedMode"/>
            <remove name="Telerik_Web_UI_SpellCheckHandler_axd"/>
            <add name="Telerik_Web_UI_SpellCheckHandler_axd" path="Telerik.Web.UI.SpellCheckHandler.axd" type="Telerik.Web.UI.SpellCheckHandler" verb="*" preCondition="integratedMode"/>
            <remove name="Telerik_Web_UI_DialogHandler_aspx"/>
            <add name="Telerik_Web_UI_DialogHandler_aspx" path="Telerik.Web.UI.DialogHandler.aspx" type="Telerik.Web.UI.DialogHandler" verb="*" preCondition="integratedMode"/>
            <remove name="Telerik_RadUploadProgressHandler_ashx"/>
            <add name="Telerik_RadUploadProgressHandler_ashx" path="Telerik.RadUploadProgressHandler.ashx" type="Telerik.Web.UI.RadUploadProgressHandler" verb="*" preCondition="integratedMode"/>
            <remove name="Telerik_Web_UI_WebResource_axd"/>
            <add name="Telerik_Web_UI_WebResource_axd" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" preCondition="integratedMode"/>
        </handlers>
    </system.webServer>
</configuration>

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 19 Sep 2011, 08:00 AM
Hello Dick,

You can try the approach in the following help article.
Checking File Size on the Client.

Thanks,
Shinu.
0
Dick
Top achievements
Rank 1
answered on 19 Sep 2011, 08:02 AM
Hi Shinu,

Thank you for your reply, but this is the exact example that we used and doesn't work.
0
Kevin
Top achievements
Rank 2
answered on 19 Sep 2011, 01:28 PM
Hello Dick,

As the help topic notes, the page continues to upload the file even though the confirmation dialog is showing. So I have to assume your uploading a file that doesn't take very long to upload, but is above 4MB in size, so the max file size is reached and the error appears.

I would re-order your code and just cancel the request and then display an alert that the file size has been reached. Either that, or increase the maxRequestLength in your web.config and see if that helps.

I hope that helps.
0
Dick
Top achievements
Rank 1
answered on 21 Sep 2011, 03:14 PM
Hi Kevin,

The confirmation dialog popup never shows. We recieve a filesize exceeded error right away.

0
Genady Sergeev
Telerik team
answered on 26 Sep 2011, 03:09 PM
Hello Dick,

Please consult with the following help article showing how to configure for large file uploads in IIS7+


Kind regards,
Genady Sergeev
the Telerik team
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 their blog feed now
Tags
Upload (Obsolete)
Asked by
Dick
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Dick
Top achievements
Rank 1
Kevin
Top achievements
Rank 2
Genady Sergeev
Telerik team
Share this question
or