Luca Steeb
Luca Steeb

Reputation: 1859

Download file from url using MVC

How can I download a file from web (e.g. a pdf file - http:/addons.cursecdn.com/files/612/825/SC1_Remake_Installation_Guide.pdf) to the client in MVC? What I tried:

    public FileResult Download()
    {
        const string name = "http://addons.cursecdn.com/files/612/825/SC1_Remake_Installation_Guide.pdf";
        const string type = "application/pdf";

        return new FilePathResult(name, type)
        {
            FileDownloadName = "SC1_Remake_Installation_Guide.pdf"
        };
    }

This is giving me only the error message that it 'is not a valid virtual path'..

Upvotes: 0

Views: 6808

Answers (1)

CubeRoot
CubeRoot

Reputation: 562

How about redirecting the client to the pdf's URL? Seems like an ok solution.

Use a regular ActionResult and use a Redirect like the following.

    return Redirect("http://addons.cursecdn.com/files/612/825/SC1_Remake_Installation_Guide.pdf");

Upvotes: 2

Related Questions