Hi Friends,
I have a big problem and i am trying for a day to solve this.
I want to down load files from the server. I have used asp.net mvc 4 solution.
My views code is like below.
$.ajax({
url: '@Url.Action("DownloadFile", "Inbox")',
type: 'POST',
cache: false,
data: {
filePaths: filePaths
},
success: function (result) {
stopPreLoader();
},
error: function (result) {
stopPreLoader();
}
});
Here filePaths is list of names of files. Further my controller is like below,
[HttpPost]
public FileResult DownloadFile(string filePaths)
{
var pathList = filePaths.Split(',').Where(p => p != "").ToList();
var path = @"" + pathList[0];
if (pathList.Count == 1)
{
byte[] fileBytes = System.IO.File.ReadAllBytes(path);
string fileName = "abc.pdf";
return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Zip, fileName);
}
if (pathList.Count > 1)
{
var id = Session.SessionID;
var archive = Server.MapPath("~/archive.zip");
var temp = Server.MapPath("~/temp");
if (System.IO.File.Exists(archive))
{
System.IO.File.Delete(archive);
}
Directory.EnumerateFiles(temp).ToList().ForEach(f => System.IO.File.Delete(f));
pathList.ForEach(f => System.IO.File.Copy(f, Path.Combine(temp, Path.GetFileName(f))));
ZipFile.CreateFromDirectory(temp, archive);
return File(archive, "application/zip", "archive.zip");
}
return null;
}
So above archive.zip file is created in the server. But I does not appear download confirmation box on the browser.
Please help me to solve this issue.
What I have tried:
I have searched every where on the internet and tried for a day.