/// <summary>
    /// Delete Post(s) click action.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbDelete_Click(object sender, EventArgs e)
    {
        bool bRemove = false;

        for (int i = 0; i < gvPosts.Rows.Count; i++)
        {
            CheckBox cb = gvPosts.Rows[i].FindControl("cb") as CheckBox;
            if (cb.Checked)
            {
                string PostID  = (gvPosts.Rows[i].FindControl("PostID") as Literal).Text;
                int    iPostID = 0;

                int.TryParse(PostID, out iPostID);

                BSPost bsPost = BSPost.GetPost(iPostID);
                bRemove = bsPost.Remove();
            }
        }
        if (bRemove)
        {
            MessageBox1.Message = Language.Admin["PostDeleted"];
            MessageBox1.Type    = MessageBox.ShowType.Information;

            gvPosts.DataBind();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request["act"]) && Request["act"].Equals("delete"))
        {
            string strPostID = Request["PostID"];
            int    iPostID   = 0;

            int.TryParse(strPostID, out iPostID);

            if (iPostID > 0)
            {
                BSPost bsPost = BSPost.GetPost(iPostID);
                if (bsPost != null)
                {
                    bsPost.Remove();
                }
            }

            Response.Redirect("AutoSaves.aspx");
        }
        rpAutoSaves.DataSource = BSPost.GetPosts(PostTypes.AutoSave, PostStates.Draft, 10);
        rpAutoSaves.DataBind();
    }
Exemple #3
0
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        string Command = "";

        for (int i = 0; i < gvPosts.Rows.Count; i++)
        {
            CheckBox cb = gvPosts.Rows[i].FindControl("cb") as CheckBox;
            if (cb.Checked)
            {
                Literal literal = gvPosts.Rows[i].FindControl("PostID") as Literal;
                if (literal != null)
                {
                    string PostID            = literal.Text;
                    BSPost bsPost            = BSPost.GetPost(Convert.ToInt32(PostID));
                    string filePath          = string.Empty;
                    string filePathWeb       = string.Empty;
                    string filePathThumbnail = string.Empty;
                    if (bsPost.Show == 0)
                    {
                        filePath = "~/Upload/Files/" + bsPost.Title;
                    }
                    else if (bsPost.Show == PostVisibleTypes.Public)
                    {
                        filePath          = "~/Upload/Images/" + bsPost.Title;
                        filePathWeb       = "~/Upload/Images/_w/" + bsPost.Title;
                        filePathThumbnail = "~/Upload/Images/_t/" + bsPost.Title;
                    }
                    else if (bsPost.Show == PostVisibleTypes.Custom)
                    {
                        filePath = "~/Upload/Medias/" + bsPost.Title;
                    }
                    filePath          = Server.MapPath(filePath);
                    filePathWeb       = Server.MapPath(filePathWeb);
                    filePathThumbnail = Server.MapPath(filePathThumbnail);
                    try
                    {
                        if (System.IO.File.Exists(filePath))
                        {
                            System.IO.File.Delete(filePath);
                        }
                        if (System.IO.File.Exists(filePathWeb))
                        {
                            System.IO.File.Delete(filePathWeb);
                        }
                        if (System.IO.File.Exists(filePathThumbnail))
                        {
                            System.IO.File.Delete(filePathThumbnail);
                        }
                    }
                    catch
                    { }

                    if (bsPost.Remove())
                    {
                        Command = "OK";
                    }
                }
            }
        }
        if (Command != "")
        {
            MessageBox1.Message = Language.Admin["MediaDeleted"];
            MessageBox1.Type    = MessageBox.ShowType.Information;

            gvPosts.DataBind();
        }
    }