I'm currently trying to build a small website in Visual Studio, ASP.net with C#. The user has to upload a file, but I only want to accept Excel files.
Currently I already have this piece of server side validation:
public ActionResult Index(HttpPostedFileBase file){
if (file != null && file.ContentLength > 0){
string fileName = Path.GetFileName(file.FileName);
if (fileName.EndsWith(".xlsx")) //enkel gewoon Excel bestand wordt aanvaard. {
...
That does the trick, but I don't know how to solely allow Excel files in the client side. I currently have this, but it doesn't limit the user yet. I can still upload whatever file I want.
<input type="file" name="file" value="Bestand kiezen" accept=".xlsx" />
I'm aware that client side limitation isn't 100% fool proof, but I'd like to implement the feature anyway. Thanks in advance!
EDIT: I got the answer thanks to the fellas below. I ended up using this, which shows .xls and .xlsx files
<input type="file" name="file" value="Bestand kiezen" accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />