/// <summary> /// 状态应用按钮事件 /// </summary> protected void btnApply_Click(object sender, EventArgs e) { try { Int32 Status = WebHelper.GetIntParam(Request, ddlStatus.UniqueID, -1); if (Status >= 0) { string Checkbox_Value = WebHelper.GetStringParam(Request, "Checkbox", ""); string[] Checkbox_Value_Array = Checkbox_Value.Split(','); Int32 IDX = 0; mTips.IsPostBack = true; for (int i = 0; i < Checkbox_Value_Array.Length; i++) { if (Int32.TryParse(Checkbox_Value_Array[i], out IDX)) { DNNGo_LayerGallery_Files Multimedia = DNNGo_LayerGallery_Files.FindByKeyForEdit(IDX); if (Multimedia != null && Multimedia.ID > 0) { //if (Multimedia.Status == (Int32)EnumFileStatus.Recycle && Status == (Int32)EnumFileStatus.Recycle) //{ //要删除实际的文件 String DeletePath = Server.MapPath(GetPhotoPath(Multimedia.FilePath)); if (Multimedia.Delete() > 0) { //删除文件 if (File.Exists(DeletePath)) { File.Delete(DeletePath); } //操作成功 mTips.LoadMessage("DeleteMediaLibrarySuccess", EnumTips.Success, this, new String[] { Multimedia.FileName }); } else { //操作失败 mTips.LoadMessage("DeleteMediaLibraryError", EnumTips.Success, this, new String[] { Multimedia.FileName }); } //} //else //{ // Multimedia.Status = Status; // if (Multimedia.Update() > 0) // { // } //} } } } BindDataList(); } } catch (Exception ex) { ProcessModuleLoadException(ex); } }
/// <summary> /// 列表上的项删除事件 /// </summary> protected void btnRemove_Click(object sender, EventArgs e) { try { LinkButton btnRemove = (LinkButton)sender; if (btnRemove != null && !String.IsNullOrEmpty(btnRemove.CommandArgument)) { mTips.IsPostBack = true; DNNGo_LayerGallery_Files Multimedia = DNNGo_LayerGallery_Files.FindByKeyForEdit(btnRemove.CommandArgument); if (Multimedia != null && Multimedia.ID > 0) { //if (Multimedia.Status == (Int32)EnumFileStatus.Recycle) //{ //要删除实际的文件 String DeletePath = Server.MapPath(GetPhotoPath(Multimedia.FilePath)); if (Multimedia.Delete() > 0) { //删除文件 if (File.Exists(DeletePath)) { File.Delete(DeletePath); } //操作成功 mTips.LoadMessage("DeleteMediaLibrarySuccess", EnumTips.Success, this, new String[] { Multimedia.FileName }); } else { //操作失败 mTips.LoadMessage("DeleteMediaLibraryError", EnumTips.Success, this, new String[] { Multimedia.FileName }); } //} //else //{ // Multimedia.Status = (Int32)EnumFileStatus.Recycle; // if (Multimedia.Update() > 0) // { // //移动到回收站操作成功 // mTips.LoadMessage("DeleteCommentSuccess", EnumTips.Success, this, new String[] { Multimedia.FileName }); // } // else // { // //移动到回收站操作失败 // mTips.LoadMessage("DeleteCommentError", EnumTips.Success, this, new String[] { Multimedia.FileName }); // } //} BindDataList(); } } } catch (Exception ex) { ProcessModuleLoadException(ex); } }
private void DeliverFile(HttpContext context) { DNNGo_LayerGallery_Files DataItem = DNNGo_LayerGallery_Files.FindByKeyForEdit(WebHelper.GetStringParam(context.Request, "PhotoID", "0")); if (DataItem != null && DataItem.ID > 0) { String Picture = GetPhotoPath(DataItem); if (!String.IsNullOrEmpty(Picture) && File.Exists(context.Server.MapPath(Picture))) { context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + DataItem.FileName + "\""); context.Response.ContentType = "application/octet-stream"; context.Response.ClearContent(); context.Response.WriteFile(context.Server.MapPath(Picture)); } else { context.Response.StatusCode = 404; } } else { context.Response.StatusCode = 404; } //var filename = context.Request["PhotoID"]; //var filePath = StorageRoot + filename; //if (File.Exists(filePath)) { // context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); // context.Response.ContentType = "application/octet-stream"; // context.Response.ClearContent(); // context.Response.WriteFile(filePath); //} else // context.Response.StatusCode = 404; }
// Delete file from the server private void DeleteFile(HttpContext context) { Int32 PhotoID = WebHelper.GetIntParam(context.Request, "ID", 0); DNNGo_LayerGallery_Files PhotoItem = DNNGo_LayerGallery_Files.FindByKeyForEdit(PhotoID); if (PhotoItem != null && PhotoItem.ID > 0) { //要删除实际的文件 String DeletePath = HttpContext.Current.Server.MapPath(GetPhotoPath(PhotoItem.FilePath)); //删除文件 if (File.Exists(DeletePath)) { try { File.Delete(DeletePath); } catch { } } //删除记录 PhotoItem.Delete(); } }