Allowing different file sizes for different document types

Last post 03-16-2011, 6:51 AM by casso. 2 replies.
Sort Posts: Previous Next
  •  02-23-2011, 4:14 AM 66388

    Allowing different file sizes for different document types

    Hi,
     
    I'm currently working on an uploader that allows images (.jpg, .gif, .png) and documents (.pdf, .doc, .docx, .xls, .xlsx, .ppt, .pptx, .txt, .rtf)
     
    I'd like to be able to set validation so that the max size of images files is 3 MB and document files is 10MB. 
     
    Is this possible? 
     
    Thanks, 
    Andrew
  •  02-23-2011, 12:19 PM 66398 in reply to 66388

    Re: Allowing different file sizes for different document types

    Dear casso,
     
    You can refer to the following snippet:

    <%@ Page Language="C#" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">  
        void InsertMsg(string msg)
        {
            ListBoxEvents.Items.Insert(0, msg);
            ListBoxEvents.SelectedIndex = 0;
        }
        void Uploader_FileUploaded(object sender, UploaderEventArgs args)
        {
            InsertMsg("File uploaded! " + args.FileName + ", " + args.FileSize + " bytes.");

            //Copys the uploaded file to a new location.
            //args.CopyTo("c:\\temp\\"+args.FileName);
            //You can also open the uploaded file's data stream.
            //System.IO.Stream data = args.OpenStream();
        }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head2" runat="server">
        <title>Selecting multiple files for upload</title>
        <link rel="stylesheet" href="demo.css" type="text/css" />
    </head>
    <body>
        <form id="form2" runat="server">
            <div class="content">
                <h2>
                    Selecting multiple files for upload</h2>
                <p>
                    Select multiple files in the file browser dialog then upload them at once</p>
                <CuteWebUI:Uploader runat="server" ID="Uploader1" InsertText="Upload Multiple Files"
                    MultipleFilesUpload="true" OnFileUploaded="Uploader_FileUploaded">             
                </CuteWebUI:Uploader>
               <br />
                <br />
                <div>
                    Server Trace:
                    <br />
                    <asp:ListBox runat="server" ID="ListBoxEvents" Width="400"></asp:ListBox>
                </div>
            </div>
        </form>
           <script type="text/javascript">
               function CuteWebUI_AjaxUploader_OnSelect(files) {
                   var selectedSize = 0;               
                   for (var i = 0; i < files.length; i++) {
                       alert(files[i].FileName);
                       if (files[i].FileName.indexOf(".pdf") != -1 && files[i].FileSize > 1024 * 1024 * 3) {
                           alert("the file size of pdf file should be less than 3M");
                           return false;
                       }
                   }
               }
                </script>
    </body>
    </html>
    Thank you for asking
    Eric@cutesoft.net  
     
     
     
  •  03-16-2011, 6:51 AM 66686 in reply to 66398

    Re: Allowing different file sizes for different document types

    This worked great, thanks.
View as RSS news feed in XML