public void Page_Load(object sender, EventArgs e) { if (IsForbidden) { return; } PageUtils.CheckRequestParameter("siteId"); var specialId = AuthRequest.GetQueryInt("specialId"); var keyword = AuthRequest.GetQueryString("keyword"); if (IsPostBack) { return; } VerifySitePermissions(ConfigManager.WebSitePermissions.Template); TbKeyword.Text = keyword; if (specialId > 0) { if (!string.IsNullOrEmpty(Request.QueryString["delete"])) { var specialInfo = SpecialManager.DeleteSpecialInfo(SiteId, specialId); AuthRequest.AddSiteLog(SiteId, "删除专题", $"专题名称:{specialInfo.Title}"); SuccessDeleteMessage(); } else if (!string.IsNullOrEmpty(Request.QueryString["download"])) { var specialInfo = SpecialManager.GetSpecialInfo(SiteId, specialId); var directoryPath = SpecialManager.GetSpecialDirectoryPath(SiteInfo, specialInfo.Url); var zipFilePath = SpecialManager.GetSpecialZipFilePath(directoryPath); PageUtils.Download(Response, zipFilePath, $"{specialInfo.Title}.zip"); return; } } RptContents.DataSource = string.IsNullOrEmpty(keyword) ? DataProvider.SpecialDao.GetSpecialInfoList(SiteId) : DataProvider.SpecialDao.GetSpecialInfoList(SiteId, keyword); RptContents.ItemDataBound += RptContents_ItemDataBound; RptContents.DataBind(); BtnAdd.Attributes.Add("onclick", ModalSpecialAdd.GetOpenWindowString(SiteId)); }
public IHttpActionResult Download() { try { var request = new AuthenticatedRequest(); var siteId = request.GetPostInt("siteId"); var specialId = request.GetPostInt("specialId"); if (!request.IsAdminLoggin || !request.AdminPermissionsImpl.HasSitePermissions(siteId, ConfigManager.SitePermissions.Specials)) { return(Unauthorized()); } var siteInfo = SiteManager.GetSiteInfo(siteId); var specialInfo = SpecialManager.GetSpecialInfo(siteId, specialId); var directoryPath = SpecialManager.GetSpecialDirectoryPath(siteInfo, specialInfo.Url); var srcDirectoryPath = SpecialManager.GetSpecialSrcDirectoryPath(directoryPath); var zipFilePath = SpecialManager.GetSpecialZipFilePath(specialInfo.Title, directoryPath); FileUtils.DeleteFileIfExists(zipFilePath); ZipUtils.CreateZip(zipFilePath, srcDirectoryPath); var url = SpecialManager.GetSpecialZipFileUrl(siteInfo, specialInfo); return(Ok(new { Value = url })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public override void Submit_OnClick(object sender, EventArgs e) { if (!Page.IsPostBack || !Page.IsValid) { return; } if (HifUpload.PostedFile == null || "" == HifUpload.PostedFile.FileName) { FailMessage("上传压缩包失败,请选择ZIP文件上传!"); return; } var filePath = HifUpload.PostedFile.FileName; if (!StringUtils.EqualsIgnoreCase(Path.GetExtension(filePath), ".zip")) { FailMessage("上传压缩包失败,必须上传ZIP文件!"); return; } var directoryPath = SpecialManager.GetSpecialDirectoryPath(SiteInfo, _specialInfo.Url); DirectoryUtils.CreateDirectoryIfNotExists(directoryPath); var zipFilePath = SpecialManager.GetSpecialZipFilePath(directoryPath); HifUpload.PostedFile.SaveAs(zipFilePath); var srcDirectoryPath = SpecialManager.GetSpecialSrcDirectoryPath(directoryPath); ZipUtils.ExtractZip(zipFilePath, srcDirectoryPath); DirectoryUtils.Copy(srcDirectoryPath, directoryPath, true); LayerUtils.Close(Page); }
public override void Submit_OnClick(object sender, EventArgs e) { if (!Page.IsPostBack || !Page.IsValid) { return; } var title = TbTitle.Text; var url = PathUtility.AddVirtualToPath(TbUrl.Text); if (_specialInfo != null) { var oldDirectoryPath = string.Empty; var newDirectoryPath = string.Empty; if (_specialInfo.Title != title && DataProvider.SpecialDao.IsTitleExists(SiteId, title)) { FailMessage("专题修改失败,专题名称已存在!"); return; } if (_specialInfo.Url != url) { if (DataProvider.SpecialDao.IsUrlExists(SiteId, url)) { FailMessage("专题修改失败,专题访问地址已存在!"); return; } oldDirectoryPath = SpecialManager.GetSpecialDirectoryPath(SiteInfo, _specialInfo.Url); newDirectoryPath = SpecialManager.GetSpecialDirectoryPath(SiteInfo, url); } _specialInfo.Title = title; _specialInfo.Url = url; DataProvider.SpecialDao.Update(_specialInfo); if (oldDirectoryPath != newDirectoryPath) { DirectoryUtils.MoveDirectory(oldDirectoryPath, newDirectoryPath, true); } } else { if (HifUpload.PostedFile == null || "" == HifUpload.PostedFile.FileName) { FailMessage("专题添加失败,请选择ZIP文件上传!"); return; } var filePath = HifUpload.PostedFile.FileName; if (!StringUtils.EqualsIgnoreCase(Path.GetExtension(filePath), ".zip")) { FailMessage("专题添加失败,必须上传ZIP文件!"); return; } if (DataProvider.SpecialDao.IsTitleExists(SiteId, title)) { FailMessage("专题添加失败,专题名称已存在!"); return; } if (DataProvider.SpecialDao.IsUrlExists(SiteId, url)) { FailMessage("专题添加失败,专题访问地址已存在!"); return; } var directoryPath = SpecialManager.GetSpecialDirectoryPath(SiteInfo, url); DirectoryUtils.CreateDirectoryIfNotExists(directoryPath); var zipFilePath = SpecialManager.GetSpecialZipFilePath(directoryPath); HifUpload.PostedFile.SaveAs(zipFilePath); var srcDirectoryPath = SpecialManager.GetSpecialSrcDirectoryPath(directoryPath); ZipUtils.ExtractZip(zipFilePath, srcDirectoryPath); DirectoryUtils.Copy(srcDirectoryPath, directoryPath, true); //var htmlFiles = Directory.GetFiles(srcDirectoryPath, "*.html", SearchOption.AllDirectories); //foreach (var htmlFile in htmlFiles) //{ // CreateManager.CreateFile(); //} var specialInfo = new SpecialInfo { Title = title, Url = url, SiteId = SiteId, AddDate = DateTime.Now }; DataProvider.SpecialDao.Insert(specialInfo); } LayerUtils.Close(Page); }