In our ASP.NET Core 1.1, EF Core 1.1 app we have populated a string with some data from SQL Server and would like to have a text file created out of it on the fly and have a user save/download from the client side.
In old days we used to do it as follows:
List<string> stringList = GetListOfStrings();
MemoryStream ms = new MemoryStream();
TextWriter tw = new StreamWriter(ms);
foreach (string s in stringList) {
tw.WriteLine(s);
}
tw.Flush();
byte[] bytes = ms.ToArray();
ms.Close();
Response.Clear();
Response.ContentType = "application/force-download";
Response.AddHeader("content-disposition", "attachment; filename=myFile.txt");
Response.BinaryWrite(bytes);
Response.End();
How can that be achieved in ASP.NET Core 1.1? Tried to follow File Providers in ASP.NET Core to no avail.
Response.ContentType
beResponse.ContentType = "application/download"
or change it toResponse.ContentType = "text";
– Thraveapplication/download
will also be ok. – Marcela