Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

361
Visualizações
Asp.net Core-choose and Validate excel file before uploading using javascript or C#?

1-How can I select only files in Excel format? enter image description here

2-How do I validate the file format in both JavaScript and C #?

I Use The EPPlus Plugin in Asp.Net Core 3.1?

Html :

<form id="SelectExcelForm" method="post">
  <div class="form-group">
    <div class="form-line">
      <input type="file" name="ExcelFile" class="form-control" />
      <span class="text text-danger">True Format : xlsx </span>
    </div>
  </div>
  <div class="modal-footer">
    <button type="button" onclick="return ValidateForm()" class="btn btn-info waves-effect">Save</button>
  </div>
</form>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

if you want to validate the file format in C# code , You can use the following code:

<input type="file" name="ExcelFile" class="form-control" accept=".xls,.xlsx" />

In this way , You can only see files in Excel format in the selection box.

When you want to use JS to validate , you can use these code:

<input type="file" name="ExcelFile" class="form-control" onchange="fileChange(this)" />

    <script>
        function fileChange(target) {
            var name=target.value;
            var fileName = name.substring(name.lastIndexOf(".")+1).toLowerCase();
            if(fileName !="xls" && fileName !="xlsx"){
                alert("please upload file in Excel forma!");
                target.value="";
                return false;   
            }
        }

    </script>

In this way , You can see files in all formats in the selection box , but when you select files in other format , It will fail to upload.

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda