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");
}
}
FileContentResult Class (Microsoft. AspNetCore. Mvc) Represents an ActionResult that when executed will write a binary file to the response.
ASP.NET will handle getting rid of this stream for you once the transfer is complete (part of the FileStreamResult), so you don't need to worry about cleaning it up.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With