1

I have a custom IHttpHandler which is used by thick clients to download files using a url such as

http://url.ashx?id=123&version=456 

the code handler basically ends with

context.Response.WriteFile(myLocalServerPath);

Is it possible to replace this using the typical asp.net mvc controller pattern ?

2 Answers 2

3

In an action:

byte[] fileBytes = ...;
string fileName = "example";
return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);

(Or a more specific MIME type if known)

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

1 Comment

If we returned a more specific MIME, it will just be displayed in the browser (in case if images), how can we download it (by using the more specific MIME)?
0

From this site but simplified:

    public FileResult Download()
    {
        string filename = "test.pdf";
        string contentType = "application/pdf";
        //Parameters to file are
        //1. The File Path on the File Server
        //2. The content type MIME type
        //3. The parameter for the file save by the browser
        return File(filename, contentType,"Report.pdf");
    }

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.