Is there any way I can save a published file on a user's PC from a published site?

3

I am creating a zipped file and need to save it to my user, but when I save the location wherever the file is saved it saves on the server where the site is hosted.

Path

string zip = @"C:\file.zip";

Moving on to be saved ...

using (var fileStream = new FileStream(zip, FileMode.Create))

How can I save direct to my user's PC?

    
asked by anonymous 09.05.2016 / 15:43

1 answer

2

You can perform the download operation and let it choose the location to save.

public FileResult Download()
{
    byte[] fileBytes = System.IO.File.ReadAllBytes(@"c:\folder\myfile.ext");
    string fileName = "myfile.ext";
    return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
}
    
09.05.2016 / 15:47