c# – How can I save a file on the user's PC from a published website?

Question:

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

Path

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

Going to be saved…

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

Is it possible for me to save directly on my user's PC?

Answer:

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

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);
}
Scroll to Top