Home > ASP.Net, Javascript > Validate FileUpload Extension

Validate FileUpload Extension


try this example to Validate FileUpload Extension using Javascript

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <script type ="text/javascript">
    var validFiles=["bmp","gif","png","jpg","jpeg"];
        function OnUpload()
          var obj = document.getElementById("<%=FileUpload1.ClientID%>");
          var source=obj.value;
          var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
          for (var i=0; i<validFiles.length; i++)
            if (validFiles[i]==ext)
          if (i>=validFiles.length)
            alert("This not a valid file upload file with an extention of one of the following:\n\n"+validFiles.join(", "));
            return false;
          return true;
    <form id="form1" runat="server">
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick ="return OnUpload();"  />

Hope this helps

Refrence her

Good Luck

Categories: ASP.Net, Javascript
  1. June 3, 2009 at 6:47 pm

    Hi Yasser,
    I have no objection if you use my code but give reference to the article.

  2. June 4, 2009 at 3:30 am



  3. RRaveen
    July 2, 2009 at 2:39 pm

    Dear Friends,

    I hope you are doing well. I have launched a web site http://www.codegain.com and it is basically aimed C#,JAVA,VB.NET,ASP.NET,AJAX,Sql Server,Oracle,WPF,WCF and etc resources, programming help, articles, code snippet, video demonstrations and problems solving support. I would like to invite you as an author and a supporter. Looking forward to hearing from you and hope you will join with us soon.

    Please forward this email to all of your friends who are related IT. Send to us your feed about site also.

    Thank you
    Founder CodeGain.com

  1. No trackbacks yet.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: