Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

351
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!