tags:

views:

66

answers:

2

Hi

I am wondering if you do something like

public FileResult result()
{
   Stream stream = new Stream();
   return File(stream,"text/html","bob.html");
}

if File() would close the stream for you? Since I tried to put the "stream" in a using statement but it always gave me a error saying the stream was closed.

public FileResult result()
{
    using(Stream stream = new Stream())
    {
       return File(stream,"text/html","bob.html");
    }
}
A: 

This might help.

Using Statement

griegs
+1  A: 

If you are using the File object to send the resulting file for download as bob.html then yes.

I believe that all standard Streams (OutputStream, FileStream, CryptoStream) will attempt to flush when closed or disposed.

There are a number of classes within the MVC framework that implement the base FileResult class.

System.Web.Mvc.FileResult
System.Web.Mvc.FileContentResult
System.Web.Mvc.FilePathResult
System.Web.Mvc.FileStreamResult
Kane
What other situations would you use File() other thank sending the file for download?
chobo2