Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Add a File method overload on controller and pages. #7232

Closed
javiercn opened this issue Jan 11, 2018 · 5 comments
Closed

Add a File method overload on controller and pages. #7232

javiercn opened this issue Jan 11, 2018 · 5 comments

Comments

@javiercn
Copy link
Member

This method (and its associated action result) will perform content negotiation, serialize the object with a formatter and set the content disposition header.

This is useful when the object being sent to the client is the in memory representation of a document and you want the client to download the document.

@mkArtakMSFT
Copy link
Contributor

@javiercn, we need more details on this. Isn't this what you get with standard action methods - which by-default get content negotiation enabled?

@javiercn
Copy link
Member Author

@mkArtakMSFT With standard action methods you only get content-negotiation, but you still have to set the content-disposition header yourself on the response. This overload streamlines that.

FileResult(object file, string fileName, string contentType)
public class ObjectFileResult : ObjectResult
{
    public string FileName { get; set; }
    public string ContentType { get; set; }

    public void override OnFormatting(ActionContext context)
    {
        SetStatusCode();
        SetContentType();
        SetContentDispositionHeader();
    }
}

@rynowak
Copy link
Member

rynowak commented Jan 11, 2018

@javiercn is this a dupe of #6260 ?

@javiercn
Copy link
Member Author

@mkArtakMSFT
Copy link
Contributor

Closing this issue as there was no community ask for this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants