1
Friends, I am trying to generate a txt, in which the user clicks on the button and automatically downloads it. It is already generating txt, but I would like to know how to write in it?
string str = "testando";
byte[] bytes = new byte[str.Length * sizeof(char)];
System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0,bytes.Length);
MemoryStream mem = new MemoryStream();
mem.Write(bytes, 0, str.Length);
Stream outStream = Response.OutputStream;
Response.ContentType = "application/text/plain";
Response.AppendHeader("Connection", "keep-alive");
Response.AppendHeader("Content-Disposition","attachment; filename = " + "teste.txt");
mem.WriteTo(outStream);
outStream.Close();
File.WriteAllText("arquivo.txt", "Texto a ser escrito...");
– Rovann Linhalis