Maximum file size

Last post 09-21-2010, 10:22 AM by Eric. 5 replies.
Sort Posts: Previous Next
  •  09-16-2010, 3:15 AM 64039

    Maximum file size

    hi,
     
    I Have a couple of questions about the maximum filesize of the ajax uploader.
    Now I'm using
    1. fileUploader.VALIDATEOPTION.MaxSizeKB = "10240" 
    for setting the maximum filesize, But actually I want a maximum size for all items together.
    The seccond problem is, i get a popup whit the error.
    I actually don't want a popup but a message on the site or something. And I want to change the text of the alert but I can't find how to do this.
    Is it possible to change?
     
  •  09-16-2010, 10:46 PM 64052 in reply to 64039

    Re: Maximum file size

    Hi pbwbart,
     
    Please try the example below
     
    1. <%@ Page Language="C#" %>   
    2.   
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
    4.   
    5. <script runat="server">   
    6.   
    7.     protected void attachment1_AttachmentRemoveClicked(object sender, AttachmentItemEventArgs args)   
    8.     {   
    9.           
    10.             hfTotalSize.Value=(int.Parse(hfTotalSize.Value)-args.Item.FileSize).ToString();   
    11.     }   
    12. </script>   
    13.   
    14. <html xmlns="http://www.w3.org/1999/xhtml">   
    15. <head runat="server">   
    16.     <title>Untitled Page</title>   
    17. </head>   
    18. <body>   
    19.     <form id="form1" runat="server">   
    20.         <CuteWebUI:UploadAttachments ID="attachment1" runat="server" OnAttachmentRemoveClicked="attachment1_AttachmentRemoveClicked">   
    21.         </CuteWebUI:UploadAttachments>   
    22.         <asp:HiddenField ID="hfTotalSize" runat="server" Value="0" />   
    23.         </form>   
    24. </body>   
    25. </html>   
    26.   
    27. <script>   
    28. var totalSize = document.getElementById("<%=hfTotalSize.ClientID %>");;   
    29. //max size setting 1024000=1mb   
    30. var MaxSizeKB=1024000;   
    31. function CuteWebUI_AjaxUploader_OnSelect(files) {   
    32.   
    33.     for (var i = 0; i < files.length; i++) {   
    34.         totalSize.value = parseInt(totalSize.value) + files[i].FileSize;   
    35.     }   
    36.   
    37.     if (parseInt(totalSize.value) > MaxSizeKB) {   
    38.         for (var j = 0; j < files.length; j++) {   
    39.             totalSize.value = parseInt(totalSize.value) - files[j].FileSize;   
    40.         }   
    41.         //handle the error message here   
    42.         alert("File size limit exceeded");   
    43.         return false;   
    44.     }   
    45.   
    46. }   
    47. </script>  
    Regards,
     
    Ken
  •  09-17-2010, 3:21 AM 64055 in reply to 64052

    Re: Maximum file size

    Thanks,
     
    For the most part this will work,
    only
    "AttachmentRemoveClicked"
    Won't be triggert while removing a file from the list so the counting goes wrong if a user deletes a file from the list
  •  09-17-2010, 11:29 AM 64065 in reply to 64055

    Re: Maximum file size

    Dear pbwbart,
     
    "attachment1_AttachmentRemoveClicked" is fired when you remove file. I have tested it. Please set breakpoint within "attachment1_AttachmentRemoveClicked" and test it again.
     
    Thank you for asking
  •  09-21-2010, 8:26 AM 64113 in reply to 64065

    Re: Maximum file size

    I created a small test to check it out
    1. Public Class _Default  
    2.     Inherits System.Web.UI.Page  
    3.   
    4.     Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
    5.   
    6.         Dim fileUploader As New CuteWebUI.UploadAttachments  
    7.         fileUploader.ID = "fileUploader"  
    8.         fileUploader.ManualStartUpload = "true"  
    9.   
    10.         AddHandler fileUploader.AttachmentRemoveClicked, AddressOf fileUploader_AttachmentRemoveClicked  
    11.         Dim btnAddFiles As New Button  
    12.         btnAddFiles.ID = " btnAddFiles"  
    13.         btnAddFiles.CssClass = "Inputbutton"  
    14.         btnAddFiles.Text = "Toevoegen"  
    15.         btnAddFiles.Attributes.Add("OnClick""document.getElementById('" & form1.ClientID & "_fileUploader').startupload();return false;")  
    16.         Dim hfTotalSize As New HiddenField  
    17.         hfTotalSize.ID = "hfTotalSize"  
    18.         hfTotalSize.Value = "0"  
    19.         form1.Controls.Add(fileUploader)  
    20.         form1.Controls.Add(New LiteralControl("<br />"))  
    21.         form1.Controls.Add(btnAddFiles)  
    22.         form1.Controls.Add(hfTotalSize)  
    23.   
    24.     End Sub  
    25.     Sub fileUploader_AttachmentRemoveClicked(ByVal sender As Object, ByVal args As CuteWebUI.AttachmentItemEventArgs)  
    26.         Dim hoi As String = "hoi"  
    27.     End Sub  
    28.   
    29. End Class 
     but if I set a debugpoint at row26 nothing happens while clicking the red cross
    So somewhere the  AttachmentRevomodeClicked isn't triggert correctly,
    Downloaded the new version of the uploadcontrol today.
     
    Regs Bart
  •  09-21-2010, 10:22 AM 64116 in reply to 64113

    Re: Maximum file size

    Dear Bart,
     
    Please refer to the following code:
    1. AjaxUploaderCodeBehindTest.aspx
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="AjaxUploaderCodeBehindTest.aspx.vb" Inherits="AjaxUploaderCodeBehindTest" %>
    <!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">
        <div>   
            <CuteWebUI:UploadAttachments ID="UploadAttachments1" runat="server" >
            </CuteWebUI:UploadAttachments>
        </div>
        </form>
    </body>
    </html>
    2.AjaxUploaderCodeBehindTest.aspx.vb

    Partial Class AjaxUploaderCodeBehindTest
        Inherits System.Web.UI.Page

        Protected Sub UploadAttachments1_FileUploaded(ByVal sender As Object, ByVal args As CuteWebUI.UploaderEventArgs) Handles UploadAttachments1.FileUploaded
            args.CopyTo("e:\\temp\\" & args.FileName)
        End Sub

        Protected Sub AttachmentRemoveClicked(ByVal sender As Object, ByVal args As CuteWebUI.AttachmentItemEventArgs) Handles UploadAttachments1.AttachmentRemoveClicked
            Dim hoi As String = "hoi"
        End Sub
    End Class
     
    Thank you for asking
    Eric@cutesoft.net
View as RSS news feed in XML