1

i have done an asp.net mvc application for uploading file: i have this View

@using (Html.BeginForm("Uploading_validation", "Akeo", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <input type="file" name="dossier" />
   <br />
    @Html.Label("Date d'expiration")

    <input type="text" id="datepicker" name="duree" />
    <br />
 <input type="submit" value="OK" />
 }

I'd like to choose only the compressed files( .zip .iso .rar) .

So how can i make them the only possibles extensions to upload and also to display only these extension when i browse the files?

Lamloumi Afif
  • 8,941
  • 26
  • 98
  • 191

2 Answers2

2

While if you want to validate it on server you can do it using the code below

var extension = Path.GetExtension(file.FileName);
    if (extension != null && extension.ToLower() != ".xlsx")
    {
       return "please upload file with extension .xlsx";
    }
rajansoft1
  • 1,336
  • 2
  • 18
  • 38
0

You can validate it on client side to check extension using jquery, go to the link to get the codes

jquery - Check for file extension before uploading

Community
  • 1
  • 1
rajansoft1
  • 1,336
  • 2
  • 18
  • 38
  • Please put a warning on that to do validation client AND server side! –  May 29 '13 at 14:10