Temp O'rary
Temp O'rary

Reputation: 5808

How to download a file created in the server's memory to the client without saving it?

How to download a file created in the server's memory to the client without saving it (ASP.NET)?

I've generated an Excel file on server using NetOffice. BUT now, I am not able to download it to the client. I don't want to save a copy of this file on the server.

Can we send the file object created in the memory using Streams?

Upvotes: 0

Views: 1205

Answers (1)

geedubb
geedubb

Reputation: 4057

Indeed you can. Just pass to Response.OutputStream of your HTTP request. Something like this should work (where yourStream is a stream from your in memory excel doc):

    Response.Clear();
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    Response.AddHeader("Content-Disposition", "attachment; filename=myfile.xlsx");
    yourStream.WriteTo(Response.OutputStream);
    Response.Flush();

Upvotes: 1

Related Questions