62,074
社区成员
发帖
与我相关
我的任务
分享
public IActionResult ZipFolder()
{
try
{
if (!Directory.Exists(".//PaPDF"))//若文件夹不存在则新建文件夹
{
Directory.CreateDirectory(".//PaPDF"); //新建文件夹
}
//获取应用程序的当前工作目录
string path = System.IO.Directory.GetCurrentDirectory() + @"\pdf.zip";
string zipPath = ".//pdf.zip"; //压缩后输出文件路径
string folderPath = ".//PaPDF//"; //压缩前的文件夹路径
(new FastZip()).CreateZip(zipPath, folderPath, true, ""); //调用SharpZipLib.dll压缩文件夹
Directory.Delete(folderPath, true); //压缩后删除文件夹
return File(path, "application/zip", "pdf.zip");
}
catch (Exception ex)
{
return Json(new { status = "Danger", msg = "下載失敗!原因:" + ex.Message });
}
}
public IActionResult ZipFolder()
{
try
{
if (!Directory.Exists(".//PaPDF"))//若文件夹不存在则新建文件夹
{
Directory.CreateDirectory(".//PaPDF"); //新建文件夹
}
//获取应用程序的当前工作目录
//string path = System.IO.Directory.GetCurrentDirectory() + @"\pdf.zip";
string zipPath = ".//pdf.zip"; //压缩后输出文件路径
string folderPath = ".//PaPDF//"; //压缩前的文件夹路径
(new FastZip()).CreateZip(zipPath, folderPath, true, ""); //调用SharpZipLib.dll压缩文件夹
Directory.Delete(folderPath, true); //压缩后删除文件夹
var stream = System.IO.File.OpenRead(zipPath);//转换为文件流的方式输出
return File(stream, "application/zip");
}
catch (Exception ex)
{
return Json(new { status = "Danger", msg = "下載失敗!原因:" + ex.Message });
}
}
$(document).on('click','#btnDown',function(){
window.location = '/DLRRP01/ZipFolder';
})