c # – Save list information in MVC txt

Good afternoon guys, since I am new to mvc I would like to receive help from you if possible, I am trying to get some data from my list, add it to a txt file and save it to my machine, what happens is that the file is generated in my c: however I can't write the information coming from my list to the file, could you help me if possible. Here is 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);
        }