Check the File size while uploading file using FileUploadControl


Client Side Code :

<asp:FileUpload ID="flimgupload" runat="server" />
                <asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server"
                    ErrorMessage="Image Extention Should be .jpg|.gif|.jpeg"
                    ControlToValidate="flimgupload"
                   
                    ValidationExpression="^.*\.((j|J)(p|P)(e|E)?(g|G)|(g|G)(i|I)(f|F)|(p|P)(n|N)(g|G))$"
                    Display="Dynamic"></asp:RegularExpressionValidator>

                    <asp:CustomValidator ID="CustomValidator1" runat="server"
                    ErrorMessage="Image Size Should not exceed 100 K"
                    OnServerValidate = "CustomValidator1_ServerValidate" Display="Dynamic"
                    ControlToValidate="flimgupload"></asp:CustomValidator>

Server Side Code :

 protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            if (args.IsValid)
            {
                if (flimgupload.PostedFile.ContentLength > 102400)
                {
                    args.IsValid = false;
                }
            }
        }

Comments

Popular posts from this blog

IRM and the Object Model

This content database has a schema version which is not supported in this farm

Activate and Deactivate Feature through PowerShell