Home > ASP.Net > Validate Fileupload Control

Validate Fileupload Control


try this example to Validate Fileupload Control to allow user to upload Doc files only

<asp:FileUpload ID="UploadFile" runat="server" />
<asp:Button Text="Save" ID="btnSave" runat="server"
OnClientClick="javascript:return ValidateUpload();" />    
<script type="text/javascript" language="javascript">
    function ValidateUpload()
                var Upload_file = document.getElementById('<%= UploadFile.ClientID %>');               
                var myfile = Upload_file.value;              
                 alert('Valid Format');
                 alert('Invalid Format');

Validating with RegularExpression validator:

<asp:FileUpload ID="UploadFile" runat="server" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Only Doc files are allowed"
ControlToValidate="UploadFile" ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.doc|.DOC)$">

Hope this helps

Good Luck

Categories: ASP.Net Tags:
  1. No comments yet.
  1. March 24, 2009 at 9:15 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: