Home > Net >  Asp.net core generates excel file and pushed to the client for the direct download
Asp.net core generates excel file and pushed to the client for the direct download

Time:05-13

This is the way to asp.net before write:
Is to generate the XLSX document flow (MemoryStream) into a byte [], pushed to the client directly by the Response. BinaryWrite method (through the Response at the same time. The AddHeader save file name to the client a default)
 
Public void PushToClient (string ShowFileName, HttpResponse Response)
{
MemoryStream ms=new MemoryStream ();
WB. Write (ms);

Response. The ContentType="application/octet - stream";
The Response. AddHeader (" the Content - the Disposition ", "legislation; Filename="+ HttpUtility. UrlEncode (ShowFileName, System. Text. Encoding. UTF8));
The Response. BinaryWrite (Ms. ToArray ());
The Response. The Flush ();
The Response. The End ();
}


But now the project core, found that Microsoft. AspNetCore. Http. HttpResponse does not provide this way!
Could you tell me how to write the code above into the core to? Thank you!
  • Related