2
I get a. csv file in my Controller. This file may contain two templates, with 2 or 5 lines.
First I have to do the validation to check if the file contains 5 lines:
var arquivo = new StreamReader(model.Arquivo.InputStream, Encoding.UTF7);
var arquivoValida = new StreamReader(model.Arquivo.InputStream, Encoding.UTF7);
if (this.TipoArquivoLCCP(arquivoValida, out listaRetorno, out numColunasLCCP, out isLCCP)) { }
private bool TipoArquivoLCCP(StreamReader arquivoLCCP, out object listaRetorno, out int numColunasLCCP, out bool isLCCP)
{
while (arquivoLCCP.Peek() > -1)
{ /* Verificação */ }
If this check returns false
, I go to the second method that does the other check:
if (!isLCCP && this.ValidarArquivo(arquivo, model.TipoPagina, model.Pais, out listaRetorno, out numColunas))
{ ... }
Method ValidarArquivo()
:
private bool ValidarArquivo(StreamReader arquivo, Enumeradores.TipoPaginaUploadColeta tipoPagina, string idPais, out object listaRetorno, out int numColunas)
{
while (arquivo.Peek() > -1)
{ ... }
The problem is that the command
while (arquivo.Peek() > -1) { ... }
always returns -1 and I can’t get inside the validations.
As you can see, I created two different variables that receive my file:
var arquivo = new StreamReader(model.Arquivo.InputStream, Encoding.UTF7);
var arquivoValida = new StreamReader(model.Arquivo.InputStream, Encoding.UTF7);
and use each of them in a method, but it still doesn’t work.
At the end of the first method that makes the validation include model.Arquivo.Inputstream.Position = 0; , and it worked
– Junior Torres