How to delete all comments at once?

Sep 7, 2010 at 5:44 PM

Hello, two of my friends are hosting their blog on my hosting space and their blogs are full of spam comments. I would like to help them to delete all comments, but it's impossible to delete those comments one by one, there are over one million spam comments between their blogs. Please help...

Coordinator
Sep 7, 2010 at 8:17 PM

Wow... do you want to delete all or you trying to sort this out somehow? I'm guessing it is nuclear option at this point but want to make sure. Also, what version of BE are they running?

Sep 7, 2010 at 8:51 PM
rtur wrote:

Wow... do you want to delete all or you trying to sort this out somehow? I'm guessing it is nuclear option at this point but want to make sure. Also, what version of BE are they running?

There're so many spam comments so I don't think I can delete only the spam, so I'm going to delete all the comments but keep the posts. I've got a warning email from my hosting provider (Godaddy) telling me my application had consumed over 25% of CPU usages from the server several times, so I must take some actions to prevent it happening again or my account could be suspended. The most possible thing came to my mind was the spam comments. Most of their posts have over 1000 (or even over 2000) spam comments following each post. What scary posts they are!

They are running the Bez mod of BE 1.6.0 (Which was modded by me to deal with the Godaddy subdirectory name appearing issue).

Coordinator
Sep 7, 2010 at 8:58 PM

If you want delete all:

1. Save this code as "deletespam.aspx" and move (FTP) file to the root of site you want to clean from all comments.

2. Go to this site and navigate to "deletespam.aspx" in the browser.

3. Click "delete all" button - all comments will be gone (if you got millions, you might wait a while...)

4. Remove page from the site.

5. Upgrade to 1.6.1 and enable recaptcha + akismet to go spam free.

Code to copy/paste:

<%@ Page Language="C#" %>
<%@ Import Namespace="BlogEngine.Core" %>
<script runat="server">
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Post.Posts.Count > 0)
        {
            for (int i = Post.Posts.Count - 1; i >= 0; i--)
            {
                if (Post.Posts[i].Comments.Count > 0)
                {
                    for (int j = Post.Posts[i].Comments.Count - 1; j >= 0; j--)
                    {
                        Comment comment = Post.Posts[i].Comments[j];
                        Post.Posts[i].RemoveComment(comment);
                    }
                }
            }
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Height="48px" 
            Text="Delete all comments!" Width="216px" onclick="Button1_Click" />
    </div>
    </form>
</body>
</html>

Sep 8, 2010 at 8:30 AM

Thanks rtur! It worked like a charm. I've successfully deleted all the spam. At first I ran the script on the host (And added a sleep(1) to prevent high CPU usage) but it took about 30 minutes to delete 2000 comments and after about one hour it's likely stopped automatically. Hope that one hour of deletion didn't trigger the CPU overload of my host, oops I didn't expect it took so long. So at last I downloaded all the posts and deleted the comments on my local IIS server. It took only a few minutes to delete.

Nov 2, 2010 at 4:01 PM

I have the same problem but when I try to run this page it gives a server error.

Nov 2, 2010 at 5:12 PM
ronc0011 wrote:

I have the same problem but when I try to run this page it gives a server error.

Did you put the page in the root directory?

Feb 11, 2011 at 10:41 AM

Thank you very much for the tip rtur, worked like a charm :)

Feb 18, 2011 at 6:17 PM

Does this still work for version 2.0? I need to delete all existing comments too.

Aug 30, 2012 at 2:48 PM

I just did this with version 2.6 and it works properly. So it should also work with version 2.0.

Aug 18, 2014 at 10:44 AM
HI rtur

This works for me.

Thanks for your help.

Regards,