Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I Create, write and then return a file in C# without saving it to disk

Tags:

c#

asp.net-mvc

I'm working on an ASP.NET MVC App that has buttons that have the server return an rdp file, which is created by my business layer.

What I want is to be able to have the server create this rdp file, then serve it, without having it stored on disk.

What would be the best way to go about this?

Thanks.

like image 532
damienc88 Avatar asked Aug 13 '10 05:08

damienc88


1 Answers

You can create the file in a MemoryStream and then serve it by using Response.Write
Also don't forget to set the ContentType to "application/rdp"

Edit: As Danny Chen suggested you can use FileStreamResult in the controller class

Stream stream = new MemoryStream();
//Fill the stream here
return new FileStreamResult(stream,"application/rdp") 
like image 70
Carlos Muñoz Avatar answered Nov 15 '22 05:11

Carlos Muñoz