Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How can you program a FileUpload control in ASP.Net 3.5 to browse for Excel files only

Posted on 2011-04-28
Medium Priority
Last Modified: 2012-06-27
Hi Experts,
I have an ASP.Net 3.5 application with VB.Net codebehind.  I use a FileUpload control in my application to allow the user to browse for a given Excel file.  How can i program the FileUpload control so that it only searches for Excel files (files with the .xls extension only)

Thank you in advance,
Question by:mainrotor
  • 2
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35484780
Hi, Is not exactly what your are asking for but I think that fit into your scenario:
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35484803
By the way, there is not way (in my knowledge) to apply a filter to the web browser file dialogue, but the technique in that link is good to workaround that.

Expert Comment

ID: 35484833
Try using the code given below. This is not exactly what you want but you help you restrict the files to be selected are only excel

if (filename.indexOf(".xls") == -1) {
  alert(filename + " in not an excel file");
} else {
  // process the file...

Accepted Solution

anillucky31 earned 2000 total points
ID: 35503023
We can not apply filter to web browser file dialogue. But you can restrict file upload control to pick only excel files with following code.

<form id="form1" runat="server">
    <asp:FileUpload ID="FileUploadControl" runat="server" />
    <asp:RegularExpressionValidator ID="regexpName" runat="server"    
                                    ErrorMessage="This is not valid excel."
                                    ValidationExpression="^(.*?).(xls|XLS|xlsx|XLSX)$" />

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Loops Section Overview
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question