I am doing an MVC App, and i am uploading a file... On Submit i am sending the file to the Controller. But before that, I need to know the file´s name and count of lines...
The only thing i can not do is to read the file. I dont know if it si possible...
This is what I have
<form action="@Url.Action("Save","PaymentUpload")" id="form" enctype="multipart/form-data" method="post">
<div class="form-group row">
<div class="col-md-9" style="float: left;">
<div class="upload-payment">
<div class="file-upload">
<input type="file" class=" btnCustom input-file" id="PaymentsFile" name="PaymentsFile" accept=".CSV">
</div>
<div class="button-process">
<span class="pull-left">
<button class="btnCustom btn-success" type="submit" id="btnTest">Process Payment</button>
</span>
</div>
</div>
</div>
</div>
</form>
On Submit I have this. On BeforeSend I check for fileName.. I need to open the file i know the number of lines...
$('form').submit(function (event) {
event.preventDefault();
var formdata = new FormData($(this).get(0));
$.ajax({
url: this.action,
type: this.method,
data: formdata,
processData: false,
contentType: false,
beforeSend: function ()
{
var fileUpload = $("#PaymentsFile").get(0);
var files = fileUpload.files;
//Get the file Name
var name = files[0].name;
//Get rows count...????
},
success: function (result) {
// processResponse(result);
},
complete: function () {
}
});
});
It is a way to achieve this?
Thanks