-1
Good afternoon guys, as I am new in mvc would like a help if possible from you, I am trying to get some data from my list add the same in a txt file and save on my machine, what this agreeing is that the file is generated in my c:However, I am not able to write the information that comes from my list inside the archive, could if possible give me a help. Here’s an example from my controller.
public IActionResult Exportar(DateTime dateTime, DateTime dateTimeFinal)
{
var Layout = _context.RegistroDePontos.Where(e => e.data >= dateTime && e.data <= dateTimeFinal).ToList();
string nomeArquivo = @"C:\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
StreamWriter writer = new StreamWriter(nomeArquivo, true);
for(int i = 0; i < Layout.Count; i++)
writer.WriteLine(Layout[i].ToString());
writer.Close();
return View("Exportar",Layout);
}
you want to write the file to the server or return it filled to the user who is using your application?
– Leandro Angelo
There’s no "nothing" wrong with your program... or you don’t have permission to write or your
context.RegistroDePontos
is not returning anything in the conditions ofWhere()
...– Leandro Angelo
In the point record the property returns only the Date or a Date and Time?
– Leandro Angelo
Leandro, Thanks for your fedback, I managed to solve problem. Vlewww
– jhonathanrsy
If the solution was not for my answer, the ideal is for you to post an answer with your resolution. But if it was, it would be nice for you to mark as accepted so that the question is completed and this can be useful for other users.
– Leandro Angelo