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

x
?
Solved

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

Posted on 2011-04-28
4
Medium Priority
?
521 Views
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,
mrotor
0
Comment
Question by:mainrotor
  • 2
4 Comments
 
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:
http://sathishmncl.blogspot.com/2010/11/file-upload-control-validation-using.html
0
 
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.
0
 
LVL 3

Expert Comment

by:kumarnimavat
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...
}  
0
 
LVL 9

Accepted Solution

by:
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."
                                    ControlToValidate="FileUploadControl"    
                                    ValidationExpression="^(.*?).(xls|XLS|xlsx|XLSX)$" />
</form>
0

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