I’m making a zip file and i want to return a downloadable file but I cant figure out the return file part even tho i tried some examples i found online.
this is the code i use for this now, it does work without the $.post() but i need it to work with jquery. all ideas are welcome
$('.zipFiles').live('click', function () {
$.post('/Home/ZipFiles');
});
//return a file
public FileResult ZipFiles()
{
var filesToZip = Session["DownloadQue"] as List<string>;
var savedZipFile = Server.MapPath("~/App_Data/") + DateTime.Now.Minute + ".zip";
if (filesToZip != null && filesToZip.Count > 0)
using (var zip = new ZipFile(savedZipFile))
{
foreach (string item in filesToZip)
{
var path = Server.MapPath(Path.Combine("~/Pics/", item));
zip.AddFile(path, @"\cf");
}
zip.Comment = "this was made online";
zip.Save();
}
return File(savedZipFile, System.Net.Mime.MediaTypeNames.Application.Zip);
}
You may return the content of file or result from an action via jQuery. Here in your code
/home/zipfilesreturn .zip content and I think that you don’t want to show/print zip content.To download a file try this: