TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Istudent Rana
1.4k
340
83.7k
file did not open after extracting zip created by DotNetZip
Feb 20 2018 2:21 PM
here I am trying create zip folders including list of files passed through ajax call and downloading the zip on success return.
I have used DotNetZip Lib to create zip. Currently my code creates zip folder with files. Files are jpeg files. When i extract the zip
and try to open the file. File does not open. It looks like file is corrupted or formatting hasnot been done right.
What is wrong in my below code?
[HttpPost]
[ValidateAntiForgeryTokenAjax]
public ActionResult Generatezip(List<string> imageList)
{
string imgRootPath = ConfigurationManager.AppSettings["filepath"] + "\\";
string imgFile = string.Empty;
string imgKey = string.Empty;
string fileName = "DaysImage_";
try
{
var ms = new MemoryStream();
if (imageList.Count > 0)
{
string[] fileNames = imageList.FirstOrDefault().ToString().ToLower().Split('\\');
fileName += fileNames[0] + fileNames[1] + fileNames[2] + ".zip";
using (ZipFile zipFile = new ZipFile())
{
foreach (var imgPath in imageList)
{
imgKey = imgPath.Substring(imgPath.LastIndexOf("\\") + 1);
imgFile = imgRootPath + imgPath;
zipFile.AddEntry(imgKey, imgFile);
//zipFile.AddFile(imgFile);
}
zipFile.Save(ms);
TempData[fileName] = ms;
// zipFile.Save(ms);
}
}
ms.Position = 0;
return Json(new { success = true, fileName }, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
Logger.LogError(ex);
return Json(new { success = false, fileName }, JsonRequestBehavior.AllowGet);
}
}
public ActionResult DownloadImageZip(string fileName)
{
var ms = TempData[fileName] as MemoryStream;
if (ms == null)
return new EmptyResult();
TempData[fileName] = null;
return File(ms, "application/zip", fileName);
}
}
Reply
Answers (
7
)
How to force mvc textbox to uppercase before saving?
WCF JSON Format - while consuming in Client side getting an