static void Main(string[] args) { ZipFile file = new ZipFile(); file.AddFile(new FileInfo(@"E:\GitHub\CMS\Easy.CMS.Web\Modules\Section\Views\SectionTemplate.Column.cshtml")); file.AddFile(new FileInfo(@"E:\GitHub\CMS\Easy.CMS.Web\Modules\Section\Views\Thumbnail\SectionTemplate.Column.png")); var fs = File.Create("templates.gz"); byte[] buffer = file.ToMemoryStream().ToArray(); fs.Write(buffer, 0, buffer.Length); fs.Close(); fs.Dispose(); }
public JsonResult UploadTemplate() { if (Request.Files.Count > 0) { try { var file = Request.Files[0]; ZipFile zipFile = new ZipFile(); var files = zipFile.ToFileCollection(file.InputStream); foreach (ZipFileInfo item in files) { if (item.RelativePath.EndsWith(".cshtml")) { using ( var fs = System.IO.File.Create(Server.MapPath("~/Modules/Section/Views") + item.RelativePath) ) { fs.Write(item.FileBytes, 0, item.FileBytes.Length); } } else if (item.RelativePath.EndsWith(".png")) { using ( var fs = System.IO.File.Create(Server.MapPath("~/Modules/Section/Views/Thumbnail") + item.RelativePath)) { fs.Write(item.FileBytes, 0, item.FileBytes.Length); } } } } catch (Exception ex) { Logger.Error(ex); return Json(new AjaxResult { Status = AjaxStatus.Error, Message = "上传的模板不正确" }); } } return Json(new AjaxResult { Status = AjaxStatus.Normal, Message = "上传成功" }); }