2

I have an application where I allow my users to upload a file of any type. I save this in the file system on the server. The application will only be accessed by two users, so I don't need to worry about uploading any dodgy files.

How do I allow my user to press a button on an MVC form to request the file be sent back via the browser and be presented with the standard save/open dialog?

I want to return any type of file, and the example I've found always specify the type of file being returned. Is there a simple example of this?

2 Answers 2

4

See FileResult and derived classes.

Sign up to request clarification or add additional context in comments.

Comments

1

An alternative approach is to set HttpContext.Response.ContentType to the proper mimetype and then writing the contents of the file with HttpContext.Response.OutputStream.Write ().

Useful if, for example, the data is not in a local file but stored in a database as a binary blob.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.