locked
AjaxFileUpload1.MaxFileSize RRS feed

  • Question

  • User348142989 posted

    Hi

    I am trying to limit the maximum file size a AjaxFileUpload control will allow.  (I am using Visual Studio 2017 RC and AJAC 16.1.1.0. with code behind in visual basic).

    On page load I try to limit file size to 75000 using AjaxFileUpload1.MaxFileSize = 75000 but this does not appear to have any effect on the control as files larger than this are still uploaded to the server.

    Within Sub UploadComplete, I can test the file size (e.filesize) and if greater than 75000, then do nothing (effectively stopping the file being uploaded to the server) or use the AjaxFileUpload1.SaveAs(serverPath + fileName).

    Within Sub UploadCompleteAll, only files that have been uploaded to my directory on the server are processed.

    How can I notify the user a file has NOT been uploaded?

    Thanks for any help.

    Thursday, January 12, 2017 12:12 AM

Answers

  • User348142989 posted

    HI

    Thanks for your reply.  I tried the script but it did not seem to work.

    Further research led me to https://github.com/DevExpress/AjaxControlToolkit/wiki/AjaxFileUpload

    One of the properties I found is MaxFileSize

    Setting this MaxFileSize="75" now limits the file upload size to 75k.  If the user tries to add a file larger than this value, an alert is displayed with file name and reason why it is not allowed.  This is exactly what I needed.

    Again, thanks.

    Have a nice day.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 12, 2017 8:48 PM

All replies

  • User2103319870 posted

    You could try one of the options mentioned in below thread which discuss the same issue 

    https://forums.asp.net/t/1940946.aspx?how+to+set+size+limit+for+ajaxfileupload

    Thursday, January 12, 2017 12:50 AM
  • User348142989 posted

    Hi

    Thanks for your reply.  I looked at that article and used the code that allows me to stop uploading files that are too large to the server.  That works well.

    Unfortunately, I cannot find a way to notify the user that one or more of their files they tried to upload has been blocked because it is too large.  The AjaxFileUpload control shows file uploaded successuflly even though the upload was blocked.

    HOW DO I NOTIFY THE USER ONE OR MORE FILES HAVE BEEN NOT UPLOADED?

    Thanks again for your quick reply.

    Thursday, January 12, 2017 12:58 AM
  • User2103319870 posted

    HOW DO I NOTIFY THE USER ONE OR MORE FILES HAVE BEEN NOT UPLOADED?

    You can use the OnClientUploadStart event to check the filesize and provide a message to use like below

    <script type="text/javascript">
                    function UploadComplete(sender, args) {
                        for (var i = 0; i < sender._filesInQueue.length; i++) {
                            if (sender._filesInQueue[0]._fileSize > 75000) { // same condition used for server side
                                alert("file exceeds file size limit");
                                sender._filesInQueue[i].setStatus("cancelled", Sys.Extended.UI.Resources.AjaxFileUpload_Canceled + ' - too large(> ' + 75000 + ' byte)!');
                                sender._filesInQueue[i]._isUploaded = true;
                            }
                        }
                    }
                </script>
    
    
                <cc1:AjaxFileUpload ID="AjaxFileUpload1" OnClientUploadStart="UploadComplete" MaximumNumberOfFiles="10" AllowedFileTypes="" runat="server" OnUploadComplete="AjaxFileUpload1_UploadComplete1" />
    

    Thursday, January 12, 2017 5:10 AM
  • User348142989 posted

    HI

    Thanks for your reply.  I tried the script but it did not seem to work.

    Further research led me to https://github.com/DevExpress/AjaxControlToolkit/wiki/AjaxFileUpload

    One of the properties I found is MaxFileSize

    Setting this MaxFileSize="75" now limits the file upload size to 75k.  If the user tries to add a file larger than this value, an alert is displayed with file name and reason why it is not allowed.  This is exactly what I needed.

    Again, thanks.

    Have a nice day.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 12, 2017 8:48 PM