Provide a download link without creating a file on the server

I want to create a file and upload it without putting myself on the server.

public ActionResult DownloadZip(Guid id){
    using (ZipFile zip = new ZipFile())
    {
        zip.Password = "123456!";
        // GenareteString();
        // add string to file
        // save zip

        //return zip to user
    }
    return View();
}

how to do it

I am using dotnetzip

+3
source share
2 answers

You are not using return View(), but something like:

return File(myMemoryStream,                           // zipped data
    System.Net.Mime.MediaTypeNames.Application.Zip,   // "application/zip"
    "default.zip");                                   // suggested download name

Several overloads are available.

Helper functions Controller.File()and Controller.View()support both types of return data obtained from ActionResult.

+4
source

You need a server to serve people. You cannot just write a function and send it to someone over the Internet without any “server” mechanism.

-3
source

All Articles