Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Provide a link to download without creating a file on the server

I want to create a file and give it to download without putting itself 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 use DotNetZip

like image 759
Mediator Avatar asked Dec 06 '25 05:12

Mediator


1 Answers

You don't use return View() but something like:

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

There are a few overloads available.

The Controller.File() and Controller.View() helper functions both return types derived from ActionResult.

like image 147
Henk Holterman Avatar answered Dec 07 '25 19:12

Henk Holterman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!