tags:

views:

75

answers:

2

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.

+5  A: 

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") 
Carlos Muñoz
Yes. MemoryStreams would be an ideal choice :)
Ranhiru Cooray
MemoryStream is OK but no Response.Write because he is using ASP.NET MVC.
Danny Chen
Response.Write does work in MVC
Carlos Muñoz
Sounds great. The business layer's written by me, and hasn't been finalised.
damienc88
@Carlos:Yes we can of course use it, but I think FileResult has a better MVC style :D
Danny Chen
Well I havent done much MVC but i knew I could use Response.Write since System.Web.Mvc.ViewPage inherits from System.Web.UI.Page. Anyway i guess FileResult could be easier
Carlos Muñoz
+1  A: 

I would use a MemoryStream object to write the data to a memory buffer.

But It all depends on your business layer, if it's fexible enough to output data to arbitrary streams.

Alternatively, if on Unix-like machine, mount a folder using ramfs and use that for temp storage, so the file is stored in memory. But I guess small chance you are using ASP.NET with Linux/BSD.

extropy